GitSheet
Simple git cheatsheet
Branches
| git branch | List all local branches. |
| git branch -a | List remote and local branches. |
| git checkout -b [branch_name] | Create a local branch and switch to it. |
| git checkout [branch_name] | Switch to an existing branch. |
| git push origin [branch_name] | Push branch to remote. |
| git branch -m [new_name] | Rename current branch. |
| git branch -d [branch_name] | Delete a local branch. |
| git push origin :[branch_name] | Delete a remote branch. |
Logs
| git log --oneline | Show commit history in single line. |
| git log -[N] | Show commit history for last [N] commits. |
| git log -p -[N] | Show commit history for last [N] commits with diff. |
| git diff | Show all local file changes in the working tree. |
| git diff [file] | Show changes made to a [file]. |
| git blame [file] | Show who changed what & when in a file. |
| git remote show origin | Show remote branches and their mapping to local. |
Cleanup
| git clean -f | Delete all untracked files. |
| git clean -df | Delete all untracked files and directories. |
| git checkout -- . | Undo local modifications to all files. |
| git reset HEAD [file] | Unstage a file. |
Tags
| git pull --tags | Get remote tags. |
| git checkout [tag_name] | Switch to an existing tag. |
| git tag | List all tags. |
| git tag -a [tag_name] -m "tag message" | Create a new tag. |
| git push --tags | Push all tags to remote repo. |
Stashes
| git stash save "stash name" && git stash | Save changes to a stash. |
| git stash list | List all stashes. |
