Cheatography
https://cheatography.com
Git cheat sheet with the most useful commandss
Diff
git diff
|
WORKSPACE vs STAGED |
git diff --staged (or --cached )
|
STAGED vs COMMITED |
git diff HEAD
|
WORKSPACE + STAGED vs COMMITED |
git diff <SHA-1>
|
WORKSPACE vs any commit (more general case of the above) |
git diff master...topic
|
Changes introduced if topic gets merged into master |
-w
|
IGNORE whitespace |
Removal
git rm README
|
Remove file from git and locally |
git rm --cached README
|
Remove file from git, but keep locally as UNTRACKED |
git reset HEAD README
|
UNSTAGE a file |
git checkout -- README
|
Revert a file back to its form from the last commit |
Stashing
git stash
|
Push all TRACKED modified files (-u to include untracked, -a to include ignored) |
git stash list
|
LIST all stashes |
git stash apply
|
APPLY the last stash |
git stash apply stash@{2}
|
APPLY a chosen stash |
git stash pop
|
APPLY stash and DELETE it |
git stash drop
|
DELETE stash |
Remotes
git remote -v
|
LIST remotes with URLs |
git remote show <origin>
|
GET details with tracked branches |
git remote add <origin> <url>
|
ADD a remote |
git remote rename <origin> <upstream>
|
RENAME remote origin to upstream |
git remote rm <origin>
|
DELETE remote |
git push <origin> --delete <feature/one>
|
DELETE branch from remote |
git fetch origin
|
FETCH all data from origin |
git pull
|
FETCH and MERGE |
git push <origin> <master>
|
PUSH branch to a remote |
git branch -vv
|
Details of local branches and what they track |
Tagging
git tag
|
LIST tags |
`-l "119.*" |
FILTER tags |
git tag -a v2.0 -m "Version 2.0"
|
CREATE annotated tag |
git tag v2.0
|
CREATE lightweight tag |
git show v2.0
|
GET tag |
git tag -d v2.0
|
DELETE tag |
git push <origin> <tag>
|
PUSH single tag |
git push <origin> --tags
|
PUSH all tags |
|
|
Rebasing
git rebase master
|
Takes commits from current branch and applies them on top of master. Master stays on previous commit, only current branch is moved |
Git Log
-p
|
See differences in each commit |
-2
|
Only 2 last commits |
master feature/one
|
Only commits between master and feature/one |
--all
|
Commits from all branches |
--stat
|
See file change statistics |
--pretty=oneline/short/full/fuller/format:{some format}
|
Formatting of output |
--oneline
|
Shorthand for --pretty=oneline |
--graph
|
Shows graph |
--since=2.weeks/2010-01-15 (or after )
|
Commits from |
--until=2021 (or before )
|
Commits to |
--author=Joe
|
Only by some author, can be used multiple times |
--grep=word
|
Filter by message content |
-S word
|
Filter by commit that changed occurence of word in code |
Example: `git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" \
--before="2008-11-01" --no-merges`
--pretty=format options
Configuration
Git configuration is stored in 3 places:
- /etc/gitconfig ( --system )
- ~/.gitconfig ( --global )
- .git/config ( --local )
Each level overwrites the previous one.
Setting up:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor code
Check some setting:
git config user.name
See all configuration and sources:
git config --list --show-origin |
|
Created By
Metadata
Favourited By
Comments
Interesting cheat sheet. Can I suggest improving readability by dropping from 3 columns to 2?
Thanks for making it!
Good idea, thanks
Format looks perfect now THANKS!
Add a Comment
Related Cheat Sheets