SlideShare a Scribd company logo
1 of 1
Download to read offline
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

Similar to git-cheat-sheet (20)

Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Session git
Session gitSession git
Session git
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
T3dd10 git
T3dd10 gitT3dd10 git
T3dd10 git
 
Git
GitGit
Git
 
Git
GitGit
Git
 
simple Git
simple Git simple Git
simple Git
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheets
 
Git training
Git trainingGit training
Git training
 
Git
GitGit
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 Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
Git
GitGit
Git
 
インフラエンジニアのためのGit入門
インフラエンジニアのためのGit入門インフラエンジニアのためのGit入門
インフラエンジニアのためのGit入門
 
Git basic
Git basicGit basic
Git basic
 
Getting started with GIT
Getting started with GITGetting started with GIT
Getting started with GIT
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
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
GitGit
Git
 

More from 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.2brecke
 
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)_1brecke
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1brecke
 
Rails_3_Cheat_Sheets
Rails_3_Cheat_SheetsRails_3_Cheat_Sheets
Rails_3_Cheat_Sheetsbrecke
 
rails-migrations_1
rails-migrations_1rails-migrations_1
rails-migrations_1brecke
 
JSP Syntax_1
JSP Syntax_1JSP Syntax_1
JSP Syntax_1brecke
 
jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1brecke
 
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.2brecke
 
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)_1brecke
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1brecke
 
git-cheat-sheet
git-cheat-sheetgit-cheat-sheet
git-cheat-sheetbrecke
 

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
 
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
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
 
Rails_3_Cheat_Sheets
Rails_3_Cheat_SheetsRails_3_Cheat_Sheets
Rails_3_Cheat_Sheets
 
rails-migrations_1
rails-migrations_1rails-migrations_1
rails-migrations_1
 
JSP Syntax_1
JSP Syntax_1JSP Syntax_1
JSP Syntax_1
 
jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1jQuery1.2.cheatsheet.v1.0_1
jQuery1.2.cheatsheet.v1.0_1
 
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
 
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
 
javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1javascript-cheat-sheet-v1_1
javascript-cheat-sheet-v1_1
 
git-cheat-sheet
git-cheat-sheetgit-cheat-sheet
git-cheat-sheet
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

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://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.