Cheatography
https://cheatography.com
Git cheat sheet with the most useful commandss
Diff
|
WORKSPACE vs STAGED |
git diff --staged
(or --cached
) |
STAGED vs COMMITED |
|
WORKSPACE + STAGED vs COMMITED |
|
WORKSPACE vs any commit (more general case of the above) |
|
Changes introduced if topic gets merged into master |
|
IGNORE whitespace |
Removal
|
Remove file from git and locally |
|
Remove file from git, but keep locally as UNTRACKED |
|
UNSTAGE a file |
|
Revert a file back to its form from the last commit |
Stashing
|
Push all TRACKED modified files ( -u
to include untracked, -a
to include ignored) |
|
LIST all stashes |
|
APPLY the last stash |
git stash apply stash@{2}
|
APPLY a chosen stash |
|
APPLY stash and DELETE it |
|
DELETE stash |
Remotes
|
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 |
|
DELETE remote |
git push <origin> --delete <feature/one>
|
DELETE branch from remote |
|
FETCH all data from origin |
|
FETCH and MERGE |
git push <origin> <master>
|
PUSH branch to a remote |
|
Details of local branches and what they track |
Tagging
|
LIST tags |
`-l "119.*" |
FILTER tags |
git tag -a v2.0 -m "Version 2.0"
|
CREATE annotated tag |
|
CREATE lightweight tag |
|
GET tag |
|
DELETE tag |
git push <origin> <tag>
|
PUSH single tag |
git push <origin> --tags
|
PUSH all tags |
|
|
Rebasing
|
Takes commits from current branch and applies them on top of master. Master stays on previous commit, only current branch is moved |
Git Log
|
See differences in each commit |
|
Only 2 last commits |
|
Only commits between master and feature/one |
|
Commits from all branches |
|
See file change statistics |
--pretty=oneline/short/full/fuller/format:{some format}
|
Formatting of output |
|
Shorthand for --pretty=oneline
|
|
Shows graph |
--since=2.weeks/2010-01-15
(or after
) |
Commits from |
--until=2021
(or before
) |
Commits to |
|
Only by some author, can be used multiple times |
|
Filter by message content |
|
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
DarrinC, 22:11 7 Dec 20
Interesting cheat sheet. Can I suggest improving readability by dropping from 3 columns to 2?
Thanks for making it!
Loreno10, 17:33 13 Dec 20
Good idea, thanks
DarrinC, 19:30 13 Dec 20
Format looks perfect now THANKS!
Add a Comment
Related Cheat Sheets