COMMIT IDENTIFICATION<branch_name> | Last commit on the branch | HEAD | Current commit (parent for next commit) | HEAD^ | parent of HEAD | HEAD~n | n-th level parent of HEAD | HEAD@{n} | HEAD n moves ago (reflog) | SHA1 ID (4-20 characters) | Unique commit identifier |
HEAD~0 == HEAD
HEAD~1 == HEAD^ WORK CYCLECreate branch for new feature git checkout develop git checkout -b fb/new_feature_branch | Add change # make changes make compile git status git add file.c git diff --cached (or --staged) git commit | Rebase git pull --rebase origin develop | Push unfinished feature branch at the EoD git push origin fb/new_feature_branch -f | Merge with develop when finished # ensure we’re rebased on latest develop git checkout develop git pull git merge fb/new_feature_branch --no-ff | Push develop git push origin develop | Remove feature branch git branch -d fb/new_feature_branch git push origin :fb/new_feature_branch |
ADD CHANGEScommit [-m "commit msg"] | Commit staged changes | commit -a | Add & commit all tracked files | commit --amend | Add changes to last commit | add [file] | Stage file | add -p | Add chunks interactively | diff --staged | Inspect staged changes |
UNDO CHANGEScheckout . | Undo uncommited changes | reset HEAD | Unstage files | reset --soft HEAD^ | Undo commit (to stage) | reset --hard HEAD^ | Undo commit | revert <commit> | Revert existing commit |
BRANCHESbranch -avv | List all branches with refs | branch <name> [<commit>] | Create branch (at <commit>) | checkout -b <branch_name> | Create & checkout new branch | checkout <branch> [file] | Checkout workspace (or file) | branch -m <new_branch_name> | Rename current branch | branch -d|-D <branch> | Delete merged/unmerged branch |
MERGEmerge <with_branch> | Merge branch (default: fast-forward) | merge <with_branch> --no-ff | Merge branch (no fast-forward) |
REBASErebase <new_root_commit> | Rebase current branch | rebase -i <start_commit> | Interactive rebase | rebase -i HEAD~n | Interactive rebase (last n commits) |
| | REMOTESremote -v | Show all remotes | remote add <name> <url> | Add remote | remote remove <name> | Remove remote |
REMOTE BRANCHESfetch [<remote>] | Get remote changes | pull [<remote>] | Get & merge remote changes | pull --rebase [<remote>] [<branch>] | Get & rebase on remote changes | push [<remote>] [<branch>] [-f] | Push local branch to remote | push -n | Dry-run push | remote prune origin | Clean all old remote branch references |
RESETreset <mode> [<commit>] | Reset current branch to <commit> | reset --soft HEAD^ | Undo commit | reset HEAD~n | Undo last n commits |
--soft - do not touch working tree/index
--mixed - resets index
--hard - resets working tree & index CHERRY-PICKcherry-pick <commit> | Apply already-existing change | rebase --onto <base> <start^> <end> | Apply set of already-existing changes |
STASHstash | Stash workdir & index | stash list | List stashes | stash pop [--index] | Apply & delete stash | stash apply [--index] | Apply stash | stash pop [stash@{n}] | Apply & delete n-th stash | stash drop [stash@{n}] | Remove n-th or latest stash | stash clear | Remove all stashes | stash branch [<new_branch>] | Create branch from a stash |
TAGStag | Liast tags | tag <tagname> [<commit>] | Add lightweight tag | tag -a <tagname> [-m “Tag message”] | Add annotated tag | tag -d <tagname> | Remove tag | push <remote> <tagname> | Push tag | push <remote> --tags | Push with all tags | push <remote> :<tagname> | Remove remote tag |
BLAMEblame <file> [-L start,stop] | Check who modified file (lines start-stop) |
REFLOGreflog | Show history of HEAD | branch <new_branch_name> <lost_commit> | Recover deleted branch |
CLEANgc | Manually clean garbage objects | clean -fd | Remove not tracked files and folders |
BISECTbisect start <bad_commit> <good_commit> | Init bisect | bisect run test_script.sh | Run automated binary-search |
Error code 125 to skip current branch |
Cheatographer
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets