Cheatography
https://cheatography.com
Git related sheets. Terminal based.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Commits
git commit -m "msg" |
Commit staged with message |
git commit -a -m -"msg" |
Stage and commit all tracked files |
git log |
Commit history |
git dff |
Show unstaged changes |
git diff --staged |
Show staged changes |
Branches
git branch |
List branches |
git branch <name> |
Create new branch |
git checkout <b> |
Switch to branch <b> |
git merge <b> |
Merge <b> into current one |
git branch -d <n> |
Delete branch <n> |
|
|
Terminology
Staging Area |
Where files go before commit (git add) |
Commit |
Snapshot of staged changes |
Branch |
A separate line of development |
Merge |
Combines changes of two branches |
Remote |
A copy of repo hosted elsewhere |
Clone |
Local clone of remote repo |
Pull |
Download and merge remote changes |
Push |
Upload your commit to remote |
Tracking File
git add <f> |
Stage a file for commit |
git add . |
Stage all files |
git restore --staged <f> |
Unstage a file |
git reset <f> |
Unstage but keep working changes |
git rm <f> |
Delete tracked file and stage removoval |
|
|
Fixing mistakes
git restore <f> |
Revert file to last commited state |
git reset --soft HEAD~<n> |
Undo last n commit, keep changes staged |
git reset --hard HEAD~<n> |
Undo last commit and discard changes |
git stash |
Temporarily save uncommitted changes |
git stash pop |
Re-apply stashed changes |
git reflog |
See all recent HEAD changes |
Remote
git remote -v |
List remotes |
git remote add origin <url> |
Add a remote named "origin" |
git push -u origin <branch> |
Push and set upstream branch |
git push |
Push commits to remote |
git pull |
Fetch and merge from remote |
git fetch |
Download latest changes without merging |
|