SlideShare uma empresa Scribd logo
1 de 28
LetsVenture
Making fundraising easy
Event: Share & Learn
Subject: Next Level Git
Date: Feb 2020
By: PARAG GUPTA
Team: MSE
© guptaparag1996@gmail.com
Common Git Commands
init, remote, clone, config
add, commit, notes, remote, push,
pull, fetch
branch, checkout, tag, describe,
merge,switch
log, shortlog,whatchanged, reflog,
status, stash, diff, blame, ls-files,
archive
reset, rebase, rm, mv, restore,
clean,tag, show, cherry-pick,revert,
squash
git ?, why git, repository,
Clone & fork
git status:
Untracked Files
Modified
Staged Files
Working tree = Untracked +
Modified
Commited:unmodified/loc
ally stored
Gitignored = Before
Untracked
There are 3 major concepts of places:
● Working Directory → files in your working directory.
● Staging Area (aka cache, index) → a temp area that git add is placed into.
● HEAD → A reference to a specific commit (think of it as a variable). Normally, it
points to the last commit in local repository. (that is, after you did git commit).
1. git init //Create local folder
2. git add <directory> , git add <file>,
git add . , git add --all or git add -A
// move file to staging area from WD
Config
git config credential.helper store or // you will be prompted to enter your
credentials
git config --global credential.helper "cache --timeout 7200"
//to enable credential caching
git config --global --unset credential.helper //unset credentials
git config –global user.name “[name]”
git config –global user.email “[email address]”
git config --list
git config --global alias.co checkout
git ls-files
git commit -a -m “add .and commit together”
git commit --amend -m "Add the remaining tracked file"
git notes add -m “my note on commit” //git notes list
git remote add origin https://........
git remote (-v)
git remote remove origin
git remote set-url origin git://new.url.here
git remote rename origin old-origin
git push (-u) <remote-name><branch> (--all, --tag)
Undo Stage Changesgit reset [<mode>] [<commit>]
//unstage,without removing the changes
//resets the current branch head to <commit>
git reset HEAD^^^
git reset --soft HEAD~10 && git commit -m "squashed last 10 commit"
git clean -f // delete untracked files from harddisk, -n(dry run)
git clean -fd //-f -d empty folder
git rm --cached my-file.js
git rm <file> // delete from harddisk too
git mv file_oldname.txt file_newname.txt
Undo Commit
git checkout -- <file> //discard changes
git checkout -- '*.c' //all .c files
git checkout -f // discard changes of all not commited files
git checkout 8a7b201 index.html //restore old version
git checkout HEAD~5 // uncommit last 5 commit
git checkout master~5 Makefile //
git checkout HEAD about.html imprint.html //restore last commit
git reset HEAD -- <file>
Undo Commit
git checkout @{yesterday}
git checkout @{2.days.ago}
git checkout @{'2 days ago'}
git checkout @{'5 minutes ago'}
git checkout @{'1 month 2 weeks 3 days 1 hour 1 second ago'}
git checkout any-branch-name@{'1 hour ago'}
You are in 'detached HEAD' state.
Bad commit
Undo and Revert
an Older Commit
git revert 2b504bee
git revert --no-commit HEAD~3..
This command reverts last 3 commits with only one commit.
A very elegant and low-risk way of undoing something!
B
R
A
N
C
H
git branch //our current branches
git show-branch --list
git branch -a // + remote branch (-r)
git branch dev_branch // create new branch
git checkout dev_branch //switch into dev_branch // dev_branch may be remote branch
git checkout - // co to previous active branch //- is the branch name. - is a alias of "@{-
1}"
git checkout -b admin-panel //create new branch +switch into admin-panel
git checkout -b <branchname> --track upstream/<branch name>
git branch -d dev_branch //delete the dev_branch
git branch -D dev_branch //delete the dev_branch
git fetch origin //fetch the remote branches
Branch, Tag
If you want to rename a branch while pointed to any branch, do:
git branch -m <oldname> <newname>
If you want to rename the current branch, you can do:
git branch -m <newname>
To set a git branch alias, execute the following:
# alias -> real branch
git symbolic-ref refs/heads/trunk refs/heads/master
With the alias in place, you can execute commands like:
git checkout trunk
Log
n, p, s,
grep “MSE”,author “PDG”,
summary, branches, oneline,
stat, shortstat,
since=”1 Feb, 2020”, after=”2 weeks ago”, before=”1 year ago”, until,
merges, no-merges,
format=“%an”, pretty=format:”custom format: %cn committed %h on %cd”
git log — foo.py bar.py
git log master..feature [all f commit not in m]
git shortlog -snec --no-merges
git whatchanged #Show logs with difference each commit introduces
git log --pretty=format:"%cn committed %h on %cd"
Diff, Blame, Archive
git diff
git diff --staged/--cached
git diff [source branch] [target branch}
git blame -- src/client/Managers/FilterData.js
git archive --output=./example_repo_archive.tar.gz --format=tar HEAD ./build
--remote=<repo>
Stash
$ git checkout B
# do some change here
$ git add .
$ git stash save 'stash of B' // or git stash only
$ git checkout A
# do some change here
$ git add .
$ git stash save 'stash of A'
$ git checkout B
$ git stash list # see the stash list with message
stash@{0}: WIP on {branch_name}: {SHA-1 of last commit} {last commit of you branch}
$ git stash apply stash@{1} # B's stash will be applied
$ git stash drop stash@{1} # remove B's stash from stash stack
git stash -p # choose which file to be stashed
git stash clean # remove/delete all stash
git stash apply # for apply your last changes from stash list
git stash apply #default to stash@{0} Latest Stash.
git stash apply stash@{12} # if you will have many stashes you can choose what stash will apply
git stash drop stash@{0} # for remove from stash list
git stash pop stash@{1} # for apply choosed stash and drop it from stash list
git stash clear #Remove all the stashed states.
merge git merge dev_branch
//merging another branch into the current
git checkout master
git merge --squash bugfix
git commit
git merge --abort
Rebase feature> git rebase master //Automated
The major benefit of rebasing is that you get
a much cleaner project history. First, it
eliminates the unnecessary merge commits
required by git merge. Second, as you can
see in the diagram, rebasing also results in
a perfectly linear project history
git merge-base feature master
The following returns the commit ID of the
original base, which you can then pass to git
rebase:
git rebase -i <commit> //Interactive
rebasing
By default, the git pull command performs a
merge, but you can force it to integrate the
remote branch with a rebase by passing it
the --rebase option.
● git merge: It is safe and we often do not worry about losing code
● git rebase: could be dangerous if being used carelessly.
Pull, Fetch and Push git pull = git fetch + git merge
update your local code with
changes from origin repos.
Note that the "push" command can
also be used to delete a remote
branch.
git push origin --delete feature
Good Practices:
Follow Forking Workflow: fork then clone.
Start a "git pull" only with a clean working copy
Never Amend Published Commits
Hey You, Yes You, You Know ?
Q: What is the .gitkeep file?
Q: What’s git cherry-pick? Cherry Pick A Range Of Commits
Operations
-f fetch
-b branch
-t --track
That's it, folks!
I hope you have enjoyed
this Git session and
learned the commands
and A few git tips you
didn't know!
Thank You :)
© guptaparag1996@gmail.com

Mais conteúdo relacionado

Mais procurados

Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheetvartmp
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer CheatsheetAbdul Basit
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践Terry Wang
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about gitSothearin Ren
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
Git training cheat sheet
Git training cheat sheetGit training cheat sheet
Git training cheat sheetSkander Hamza
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - GitCarlo Bernaschina
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changesLearningTech
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nadaLama K Banna
 

Mais procurados (17)

Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer Cheatsheet
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git
GitGit
Git
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git Tricks
Git TricksGit Tricks
Git Tricks
 
Git training cheat sheet
Git training cheat sheetGit training cheat sheet
Git training cheat sheet
 
Git submodule
Git submoduleGit submodule
Git submodule
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - Git
 
Git commands
Git commandsGit commands
Git commands
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nada
 

Semelhante a Git

How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get GitSusan Tan
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With GitHoffman Lab
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221Shinho Kang
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Brian K. Vagnini
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierChristoph Matthies
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 

Semelhante a Git (20)

Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
Git
GitGit
Git
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easier
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Git

  • 2. Event: Share & Learn Subject: Next Level Git Date: Feb 2020 By: PARAG GUPTA Team: MSE © guptaparag1996@gmail.com
  • 3. Common Git Commands init, remote, clone, config add, commit, notes, remote, push, pull, fetch branch, checkout, tag, describe, merge,switch log, shortlog,whatchanged, reflog, status, stash, diff, blame, ls-files, archive reset, rebase, rm, mv, restore, clean,tag, show, cherry-pick,revert, squash
  • 4. git ?, why git, repository, Clone & fork
  • 5. git status: Untracked Files Modified Staged Files Working tree = Untracked + Modified Commited:unmodified/loc ally stored Gitignored = Before Untracked There are 3 major concepts of places: ● Working Directory → files in your working directory. ● Staging Area (aka cache, index) → a temp area that git add is placed into. ● HEAD → A reference to a specific commit (think of it as a variable). Normally, it points to the last commit in local repository. (that is, after you did git commit).
  • 6.
  • 7. 1. git init //Create local folder 2. git add <directory> , git add <file>, git add . , git add --all or git add -A // move file to staging area from WD
  • 8. Config git config credential.helper store or // you will be prompted to enter your credentials git config --global credential.helper "cache --timeout 7200" //to enable credential caching git config --global --unset credential.helper //unset credentials git config –global user.name “[name]” git config –global user.email “[email address]” git config --list git config --global alias.co checkout git ls-files
  • 9. git commit -a -m “add .and commit together” git commit --amend -m "Add the remaining tracked file" git notes add -m “my note on commit” //git notes list git remote add origin https://........ git remote (-v) git remote remove origin git remote set-url origin git://new.url.here git remote rename origin old-origin git push (-u) <remote-name><branch> (--all, --tag)
  • 10. Undo Stage Changesgit reset [<mode>] [<commit>] //unstage,without removing the changes //resets the current branch head to <commit> git reset HEAD^^^ git reset --soft HEAD~10 && git commit -m "squashed last 10 commit" git clean -f // delete untracked files from harddisk, -n(dry run) git clean -fd //-f -d empty folder git rm --cached my-file.js git rm <file> // delete from harddisk too git mv file_oldname.txt file_newname.txt
  • 11. Undo Commit git checkout -- <file> //discard changes git checkout -- '*.c' //all .c files git checkout -f // discard changes of all not commited files git checkout 8a7b201 index.html //restore old version git checkout HEAD~5 // uncommit last 5 commit git checkout master~5 Makefile // git checkout HEAD about.html imprint.html //restore last commit git reset HEAD -- <file>
  • 12. Undo Commit git checkout @{yesterday} git checkout @{2.days.ago} git checkout @{'2 days ago'} git checkout @{'5 minutes ago'} git checkout @{'1 month 2 weeks 3 days 1 hour 1 second ago'} git checkout any-branch-name@{'1 hour ago'} You are in 'detached HEAD' state.
  • 13. Bad commit Undo and Revert an Older Commit git revert 2b504bee git revert --no-commit HEAD~3.. This command reverts last 3 commits with only one commit. A very elegant and low-risk way of undoing something!
  • 14.
  • 15.
  • 16. B R A N C H git branch //our current branches git show-branch --list git branch -a // + remote branch (-r) git branch dev_branch // create new branch git checkout dev_branch //switch into dev_branch // dev_branch may be remote branch git checkout - // co to previous active branch //- is the branch name. - is a alias of "@{- 1}" git checkout -b admin-panel //create new branch +switch into admin-panel git checkout -b <branchname> --track upstream/<branch name> git branch -d dev_branch //delete the dev_branch git branch -D dev_branch //delete the dev_branch git fetch origin //fetch the remote branches
  • 17. Branch, Tag If you want to rename a branch while pointed to any branch, do: git branch -m <oldname> <newname> If you want to rename the current branch, you can do: git branch -m <newname> To set a git branch alias, execute the following: # alias -> real branch git symbolic-ref refs/heads/trunk refs/heads/master With the alias in place, you can execute commands like: git checkout trunk
  • 18. Log n, p, s, grep “MSE”,author “PDG”, summary, branches, oneline, stat, shortstat, since=”1 Feb, 2020”, after=”2 weeks ago”, before=”1 year ago”, until, merges, no-merges, format=“%an”, pretty=format:”custom format: %cn committed %h on %cd”
  • 19. git log — foo.py bar.py git log master..feature [all f commit not in m] git shortlog -snec --no-merges git whatchanged #Show logs with difference each commit introduces git log --pretty=format:"%cn committed %h on %cd"
  • 20. Diff, Blame, Archive git diff git diff --staged/--cached git diff [source branch] [target branch} git blame -- src/client/Managers/FilterData.js git archive --output=./example_repo_archive.tar.gz --format=tar HEAD ./build --remote=<repo>
  • 21. Stash $ git checkout B # do some change here $ git add . $ git stash save 'stash of B' // or git stash only $ git checkout A # do some change here $ git add . $ git stash save 'stash of A' $ git checkout B $ git stash list # see the stash list with message stash@{0}: WIP on {branch_name}: {SHA-1 of last commit} {last commit of you branch} $ git stash apply stash@{1} # B's stash will be applied $ git stash drop stash@{1} # remove B's stash from stash stack git stash -p # choose which file to be stashed git stash clean # remove/delete all stash git stash apply # for apply your last changes from stash list git stash apply #default to stash@{0} Latest Stash. git stash apply stash@{12} # if you will have many stashes you can choose what stash will apply git stash drop stash@{0} # for remove from stash list git stash pop stash@{1} # for apply choosed stash and drop it from stash list git stash clear #Remove all the stashed states.
  • 22. merge git merge dev_branch //merging another branch into the current git checkout master git merge --squash bugfix git commit git merge --abort
  • 23. Rebase feature> git rebase master //Automated The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge. Second, as you can see in the diagram, rebasing also results in a perfectly linear project history git merge-base feature master The following returns the commit ID of the original base, which you can then pass to git rebase: git rebase -i <commit> //Interactive rebasing By default, the git pull command performs a merge, but you can force it to integrate the remote branch with a rebase by passing it the --rebase option. ● git merge: It is safe and we often do not worry about losing code ● git rebase: could be dangerous if being used carelessly.
  • 24. Pull, Fetch and Push git pull = git fetch + git merge update your local code with changes from origin repos. Note that the "push" command can also be used to delete a remote branch. git push origin --delete feature
  • 25. Good Practices: Follow Forking Workflow: fork then clone. Start a "git pull" only with a clean working copy Never Amend Published Commits
  • 26. Hey You, Yes You, You Know ? Q: What is the .gitkeep file? Q: What’s git cherry-pick? Cherry Pick A Range Of Commits
  • 28. That's it, folks! I hope you have enjoyed this Git session and learned the commands and A few git tips you didn't know! Thank You :) © guptaparag1996@gmail.com

Notas do Editor

  1. Most people have no idea how dangerous life as a software developer can be: You can delete the wrong files, code into a completely wrong direction, or mess up the whole project with a single commit.
  2. A fork is just a request for GitHub to clone the project and registers it under your username; Forked Repo: personal public repository, Shared Central Repo,bare repo,all changes available, Using Github, server-side copy,server-side clones Cloned Repo: local Copied Repo,Using Git,
  3. git init -bare git init creates an empty Git repository or re-initializes an existing one. It basically creates a .git directory with subdirectories and template files. Staging is the practice of adding files for your next commit. It allows you to choose which files to commit next.
  4. Staging is the practice of adding files for your next commit. It allows you to choose which files to commit next.
  5. core.editor color.ui
  6. you should only use --amend on local commits that you haven’t yet pushed to a remote repository. The reason for this is that --amend rewrites the given commit, replacing it entirely with the fixed version. -u Creates an upstream tracking connection and is especially useful when publishing a local branch on a remote for the first time. i.e. provides default values for the push command:
  7. mode = { hard: "remove from tree,stage and wd", mixed: "remove from tree,stage", soft: "remove from tree only" }; -- is a special argument that tells Git that the arguments that follow it are paths; those before it are something else (command options, remote names, branch names, tag names etc.) –cached will only remove files from the index. Your files will still be there as untracked. With the git checkout command, we restored specific files. With the git reset command, on the other hand, we can restore our whole working copy! Or, to put it another way: this will reset your complete project to the state that was last committed. i.e. you can restore your complete project to an earlier revision.
  8. commit === check in checkout opposite of commit move HEAD back, for specific file In cases where not all of your changes in a certain file are bad, you might consider discarding just individual lines in a changed file. Use git reset
  9. commit === check in checkout opposite of commit move HEAD back, for specific file In cases where not all of your changes in a certain file are bad, you might consider discarding just individual lines in a changed file. Use git reset
  10. Many times you only notice that you made a mistake much later after it has long been committed to the repository. The question then is: how can you get rid of this bad commit? The answer is: by using the git revert command.
  11. When using this command, you might be surprised at the result - because the bad commit has not been deleted! Instead of deleting the commit, Git has automatically created a new commit with changes that revert the effects of our “bad” commit.
  12. use branches to store various versions of your project, Git repository is a tree of commits /* The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use -D, which is an alias for --delete --force, which deletes the branch "irrespective of its merged status." */
  13. Tagging is an additional mechanism used to create a snap shot of a Git repo. Tagging is traditionally used to create semantic version number identifier tags that correspond to software release cycles. The difference between tags and branches are that a branch always points to the top of a development line and will change when a new commit is pushed whereas a tag will not change. Thus tags are more useful to "tag" a specific version and the tag will then always stay on that version and usually not be changed.
  14. p: with code s: summary stat: insertion & deletion
  15. shortlog: group by author snec:summary sort email committer 'git log' shows each commit (sha, author, date, message) whereas 'git whatchanged' shows the commit plus files that changed.
  16. git blame only operates on individual files. git blame displays the last author that modified a line
  17. The first thing to understand about git rebase is that it solves the same problem as git merge. Both of these commands are designed to integrate changes from one branch into another branch—they just do it in very different ways. Ugly git history, it is hard to trace the individual commit
  18. The golden rule of git rebase is to never use it on public branches. Rebasing results in brand new commits Interactive rebasing ( -i ) allow you to alter commits pick (order), fixup (condense/squash in upper pick) avoid using git rebase after creating the pull request
  19. git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transfering. It’s more like just checking to see if there are any changes available). git pull on the other hand does that AND brings (copy) those changes from the remote repository.
  20. the Forking Workflow begins with an official public repository stored on a server. But when a new developer wants to start working on the project, they do not directly clone the official repository. you should not have any uncommitted local changes before you pull.
  21. You may know.gitignore very well. But what is .gitkeep? By default, Git doesn’t track empty directories. A file must exist within it. We can use the .gitkeep file to add empty directories into a git repo. git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Git maintains a list of checkpoints which can accessed using reflog. You can use reflog to undo merges, recover lost commits or branches and a lot more.