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

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

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.