git_cheat_sheet
git_cheat_sheet
Staging area The -a option to the git commit command makes Git automatically stage gi t c hec k out <f i l es >
/ index every file that is already tracked before doing the commit. gi t r es et - - har d HEAD <f i l es > gi t c hec k out - - <f i l es > gi t r m <f i l e> gi t r m - f <f i l e> git rm --cached <file> gi t mv <f i l eA> <f i l eB>
/ cache
Remove staged and working directory Checkout the project / unmodify a modified rm <file> remove staged changes remove staged changes mv <fileA> <fileB>
s t aged gi t add <f i l es > gi t r es et HEAD <f i l es > rm <file>
changes. file: actually overwrite files from the git add <file> untrack the file git rm <fileA>
working directory by the ones in the staged git add <file> keep file in local directory git add <fileB>
Stage a file. Unstage a staged file.
Working location or by the ones from latest commit
directory from the specified branch.
modi f i ed
gi t c onf i g - - l i s t git tag <tag string identifier> git tag Unt r ac k ed Unmodi f i ed Modi f i ed St aged
gi t c onf i g - - s y s t em /etc/gitconfig
Some keys may appear more than once, because reading in all Create a lightweight tag just a pointer to the last commit ID of the List all tags of the current branch.
configuration files. current branch. Add t he f i l e
More specific
.gitconfig
gi t c onf i g - - gl obal
config gi t c onf i g - - gl obal us er . name " J ohn Doe" git tag -a <tag string identifier> [<commit id>] git tag -l <search pattern> Edi t t he f i l e
or
supersedes/ St age t he f i l e
~/.config/git/config gi t c onf i g - - gl obal us er . emai l j ohndoe@ex ampl e. c om git tag -a <tag string identifier> -m "Tagging log message" [<commit id>] Search for a tag matching the Remov e t he f i l e
overrides
higher levels search pattern (wildcard ~regex
gi t c onf i g - - gl obal al i as . <s hor t c ut > <gi t c ommand> Create a tag (a commit) with a pointer to the last commit ID of the Commi t t he f i l e
supported).
gi t c onf i g ./.git/config current branch and a message log. Has a dedicated SHA-1 ID.
gi t c onf i g - - gl obal al i as . <s hor t c ut > ' ! <c ommand>'
gi t c l one <gi t r epo ur l > gi t pus h gi t r emot e - v gi t r emot e add <s hor t name> <r emot e ur l >
gi t c l one <gi t r epo ur l > <di r ec t or y t o c l one t o> Push the default branch master (the default one from List the shortnames of each remote handle you?ve specified. -v Add a new remote explicitely (contrary to the implicit "or i gi n"
remote.* .push) to the default remote repo called origin. adds the remote URL (pull and push) next to it. made by the "gi t c l one" command) and reference to it as the
Implicitly create a default remote repository shortname called "or i gi n", specified shortname.
download the default branch content and name that branch "master ". gi t pus h <r emot e r epo name> <l oc al br anc h> gi t r emot e s how <r emot e r epo s hor t name>
gi t r emot e r m <s hor t name>
gi t pul l As local branchs are not pushed by default, push the local Show the branches the remote repository has, which one we
branch to the remote location specified. track and which ones are concerned (tracked) when doing a pull Remove the specified remote either because the server has
If the current branch is tracking a remote branch, automatically fetch and If we do not have write access or if someone has pushed data in or a push. Untracked (aka "new") branches will be downloaded changed, the mirror is not used anymore or no one uses that
merge that remote branch into the current branch. Tags are pulled too. the meanwhile, the push is rejected and we will have to f et c h with "gi t f et c h <r emot e>". mirror any more.
and mer ge first to continue.
gi t f et c h <r emot e r epo s hor t name> gi t r emot e r ename <s hor t name> <new s hor t name>
Download all the changes made on the remote shortname location, i.e. all gi t pus h <r emot e r epo name> <t ag number > Change the remote shortname to the new one you specified.
objects (and thus commit history) are downloaded, all remote pointers will be Remote tracked branches are renamed in the process.
updated (r ef s / r emot es / * ). It doesn't automatically merge the changes with gi t pus h <r emot e r epo name> - - t ags
files from working directory nor does it modify these files.
Tags are not pushed by default. Push the tag/all tags manually.
Caption: Working
directory
The red cross means typing the command may involve data loss.
modi f i ed
This Git cheat sheet has been made by William Gathoye (@wget42) and is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-nc-sa/4.0/).
Schemas and texts are inspired from the book progit2 (http://progit.org/) written by Scott Chacon (@chacon) and Ben Straub (@benstraub) and licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License (http://creativecommons.org/licenses/by-nc-sa/3.0/).
The Git logo has been made by Jason Long (@jasonlong) and is licensed under the Creative Commons Attribution 3.0 Unported License (http://creativecommons.org/licenses/by/3.0/). The colorscheme of this sheet is inspired from that Git logo. v . 2016- 08- 15 12: 20