SlideShare a Scribd company logo
Commands Sequence
        Git Cheat Sheet                                                                                                                                                                                      the curves indicate that the command on the right is usually
                                                                                                                                                                                                             executed after the command on the left. This gives an idea of
                                        http://git.or.cz/                                                                                                                                                    the flow of commands someone usually does with Git.



             Remember: git command --help

             Global Git configuration is stored in $HOME/.gitconfig (git config --help)

                                                                                                                                            CREATE         BROWSE           CHANGE              REVERT         UPDATE                            BRANCH           COMMIT            PUBLISH

                                                                                                                                             init         status                                 reset         pull                           checkout          commit              push
                                                                                                                                            clone           log                                checkout       fetch
                                                                                                                                                           show                                 revert        merge                            branch                         format-patch
                                                                                                                                                            diff                                               am
                                                                                                                                                          branch
        Create                                             Concepts
      From existing data
        cd ~/projects/myproject
                                                           Git Basics
        git init                                           master    : default development branch
        git add .                                          origin    : default upstream repository
                                                           HEAD      : current branch
      From existing repo                                   HEAD^     : parent of HEAD
                                                           HEAD~4    : the great-great grandparent of HEAD
        git clone ~/existing/repo ~/new/repo
        git clone git://host.org/project.git
        git clone ssh://you@host.org/proj.git              Revert
        Show                                               Return to the last committed state
                                                           git reset --hard
      Files changed in working directory
                                                                                !    you cannot undo a hard reset
                                                                                                                                 Update                                                                     Publish
       git status                                          Revert the last commit
                                                                                                                                  Fetch latest changes from origin                                          Commit all your local changes
                                                           git revert HEAD           Creates a new commit
      Changes to tracked files                                                                                                        git fetch                                                             git commit -a
       git diff                                            Revert specific commit                                                     (but this does not merge them).
                                                           git revert $id            Creates a new commit
                                                                                                                                 Pull latest changes from origin                                            Prepare a patch for other developers
      What changed between $ID1 and $ID2                                                                                              git pull
                                                           Fix the last commit                                                                                                                              git format-patch origin
       git diff $id1 $id2                                                                                                              (does a fetch followed by a merge)
                                                           git commit -a --amend
      History of changes                                       (after editing the broken files)                                  Apply a patch that some sent you                                           Push changes to origin
       git log                                                                                                                        git am -3 patch.mbox                                                  git push
                                                           Checkout the $id version of a file
      History of changes for file with diffs                                                                                                         (in case of a conflict, resolve and use
                                                           git checkout $id $file                                                                     git am --resolved )
       git log -p $file $dir/ec/tory/                                                                                                                                                                       Mark a version / milestone
      Who changed what and when in a file                  Branch                                                                                                                                           git tag v1.0
       git blame $file
                                                          Switch to the $id branch
      A commit identified by $ID                           git checkout $id                                                             Finding regressions                                                                              To view the merge conclicts




                                                                                                                                                                                                               Resolve Merge Conflicts
       git show $id                                                                                                                        git bisect start             (to start)                                                        git diff      (complete conflict diff)
                                                          Merge branch1 into branch2
                                                                                                                    Useful Commands




                                                                                                                                           git bisect good $id          ($id is the last working version)                                 git diff --base $file         (against base file)
      A specific file from a specific $ID                  git checkout $branch2                                                           git bisect bad $id           ($id is a broken version)                                         git diff --ours $file         (against your changes)
       git show $id:$file                                  git merge branch1                                                                                                                                                              git diff --theirs $file       (against other changes)
                                                                                                                                           git bisect bad/good            (to mark it as bad or good)
                                                           Create branch named $branch based on                                            git bisect visualize          (to launch gitk and mark it)
      All local branches
                                                           the HEAD                                                                        git bisect reset              (once you're done)
                                                                                                                                                                                                                                         To discard conflicting patch
       git branch                                           git branch $branch
            (star '*' marks the current branch)                                                                                                                                                                                            git reset --hard
                                                           Create branch $new_branch based on                                           Check for errors and cleanup repository                                                            git rebase --skip
                                                           branch $other and switch to it                                                  git fsck
Cheat Sheet Notation                                        git checkout -b $new_branch $other                                             git gc --prune
                                                                                                                                                                                                                                         After resolving conflicts, merge with
$id : notation used in this sheet to represent either a                                                                                 Search working directory for foo()
commit id, branch or a tag name
                                                          Delete branch $branch                                                                                                                                                            git add $conflicting_file          (do for all resolved files)
                                                           git branch -d $branch                                                           git grep "foo()"                                                                                git rebase --continue
$file : arbitrary file name
$branch : arbitrary branch name                                                                                                                                                                                                                                                                   Zack Rusin
                                                                                                                                                                                                                                                                                                  Based on the work of:
                                                                                                                                                                                                                                                                                                  Sébastien Pierre
                                                                                                                                                                                                                                                                                                  Xprima Corp.

More Related Content

Similar to git-cheat-sheet (20)

Git commands
Git commandsGit commands
Git commands
Javed Hussain
 
Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15
Chen-Han Hsiao
 
Git for the Android Developer
Git for the Android DeveloperGit for the Android Developer
Git for the Android Developer
Effective
 
Git for the Android Developer
Git for the Android DeveloperGit for the Android Developer
Git for the Android Developer
EffectiveUI
 
SCM for Android Developers Using Git
SCM for Android Developers Using GitSCM for Android Developers Using Git
SCM for Android Developers Using Git
Tony Hillerson
 
Use git the proper way
Use git the proper wayUse git the proper way
Use git the proper way
Jaime Buelta
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Pham Quy (Jack)
 
Git For The Android Developer
Git For The Android DeveloperGit For The Android Developer
Git For The Android Developer
Effective
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
Peter Carenza
 
Git
GitGit
Git
Gayan Kalanamith Mannapperuma
 
git-presentation.pdf
git-presentation.pdfgit-presentation.pdf
git-presentation.pdf
2022bcacsbshubh12897
 
Using git in eclipse by Chris Aniszczyk
Using git in eclipse by Chris AniszczykUsing git in eclipse by Chris Aniszczyk
Using git in eclipse by Chris Aniszczyk
EclipseDayParis
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
Arnaud Seilles
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheets
ozone777
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Ananth Kumar
 
Git tricks
Git tricksGit tricks
Git tricks
Arthur Zapparoli
 
Git Tricks
Git TricksGit Tricks
Git Tricks
Vagner Rodrigues
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
Lorna Mitchell
 
Git Cards - Keynote Format
Git Cards - Keynote FormatGit Cards - Keynote Format
Git Cards - Keynote Format
Adam Lowe
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 

More from brecke (11)

jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2
brecke
 
jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1
brecke
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
brecke
 
git-cheat-sheet
git-cheat-sheetgit-cheat-sheet
git-cheat-sheet
brecke
 
Rails_3_Cheat_Sheets
Rails_3_Cheat_SheetsRails_3_Cheat_Sheets
Rails_3_Cheat_Sheets
brecke
 
rails-migrations_1
rails-migrations_1rails-migrations_1
rails-migrations_1
brecke
 
JSP Syntax_1
JSP Syntax_1JSP Syntax_1
JSP Syntax_1
brecke
 
jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1
brecke
 
jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2
brecke
 
jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1
brecke
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
brecke
 
jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2
brecke
 
jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1
brecke
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
brecke
 
git-cheat-sheet
git-cheat-sheetgit-cheat-sheet
git-cheat-sheet
brecke
 
Rails_3_Cheat_Sheets
Rails_3_Cheat_SheetsRails_3_Cheat_Sheets
Rails_3_Cheat_Sheets
brecke
 
rails-migrations_1
rails-migrations_1rails-migrations_1
rails-migrations_1
brecke
 
JSP Syntax_1
JSP Syntax_1JSP Syntax_1
JSP Syntax_1
brecke
 
jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1
brecke
 
jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2jQuery-Visual-Cheat-Sheet-1.4.2
jQuery-Visual-Cheat-Sheet-1.4.2
brecke
 
jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1jQuery Visual Cheat Sheet (by WOORK)_1
jQuery Visual Cheat Sheet (by WOORK)_1
brecke
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
brecke
 
Ad

Recently uploaded (20)

TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Grannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI ExperiencesGrannie’s Journey to Using Healthcare AI Experiences
Grannie’s Journey to Using Healthcare AI Experiences
Lauren Parr
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Ad

git-cheat-sheet

  • 1. Commands Sequence Git Cheat Sheet the curves indicate that the command on the right is usually executed after the command on the left. This gives an idea of http://git.or.cz/ the flow of commands someone usually does with Git. Remember: git command --help Global Git configuration is stored in $HOME/.gitconfig (git config --help) CREATE BROWSE CHANGE REVERT UPDATE BRANCH COMMIT PUBLISH init status reset pull checkout commit push clone log checkout fetch show revert merge branch format-patch diff am branch Create Concepts From existing data cd ~/projects/myproject Git Basics git init master : default development branch git add . origin : default upstream repository HEAD : current branch From existing repo HEAD^ : parent of HEAD HEAD~4 : the great-great grandparent of HEAD git clone ~/existing/repo ~/new/repo git clone git://host.org/project.git git clone ssh://[email protected]/proj.git Revert Show Return to the last committed state git reset --hard Files changed in working directory ! you cannot undo a hard reset Update Publish git status Revert the last commit Fetch latest changes from origin Commit all your local changes git revert HEAD Creates a new commit Changes to tracked files git fetch git commit -a git diff Revert specific commit (but this does not merge them). git revert $id Creates a new commit Pull latest changes from origin Prepare a patch for other developers What changed between $ID1 and $ID2 git pull Fix the last commit git format-patch origin git diff $id1 $id2 (does a fetch followed by a merge) git commit -a --amend History of changes (after editing the broken files) Apply a patch that some sent you Push changes to origin git log git am -3 patch.mbox git push Checkout the $id version of a file History of changes for file with diffs (in case of a conflict, resolve and use git checkout $id $file git am --resolved ) git log -p $file $dir/ec/tory/ Mark a version / milestone Who changed what and when in a file Branch git tag v1.0 git blame $file Switch to the $id branch A commit identified by $ID git checkout $id Finding regressions To view the merge conclicts Resolve Merge Conflicts git show $id git bisect start (to start) git diff (complete conflict diff) Merge branch1 into branch2 Useful Commands git bisect good $id ($id is the last working version) git diff --base $file (against base file) A specific file from a specific $ID git checkout $branch2 git bisect bad $id ($id is a broken version) git diff --ours $file (against your changes) git show $id:$file git merge branch1 git diff --theirs $file (against other changes) git bisect bad/good (to mark it as bad or good) Create branch named $branch based on git bisect visualize (to launch gitk and mark it) All local branches the HEAD git bisect reset (once you're done) To discard conflicting patch git branch git branch $branch (star '*' marks the current branch) git reset --hard Create branch $new_branch based on Check for errors and cleanup repository git rebase --skip branch $other and switch to it git fsck Cheat Sheet Notation git checkout -b $new_branch $other git gc --prune After resolving conflicts, merge with $id : notation used in this sheet to represent either a Search working directory for foo() commit id, branch or a tag name Delete branch $branch git add $conflicting_file (do for all resolved files) git branch -d $branch git grep "foo()" git rebase --continue $file : arbitrary file name $branch : arbitrary branch name Zack Rusin Based on the work of: Sébastien Pierre Xprima Corp.