Cheat sheet

Every command, one search away.

Setup

git init

Start tracking a new folder

git config --global user.name "Name"

Set your commit identity

git config --global user.email "you@example.com"

Set your commit email

Basics

git add <file>

Stage a change

git commit -m "message"

Save a permanent snapshot

git status

See what's changed and staged

git log

View commit history

Branching

git branch <name>

Create a branch

git checkout <name>

Switch to a branch

git merge <name>

Combine a branch into the current one

git stash

Save unfinished work temporarily

git stash pop

Restore the most recent stash

Remote

git clone <url>

Copy a remote repository locally

git fetch origin

Download remote changes without merging

git rebase origin/master

Replay local commits on updated history

git merge <name> --no-ff -m "msg"

Force a merge commit with a custom message

Tags & Advanced

git tag <name>

Mark a commit as a release point

git push origin <tag>

Push a tag to the remote

git cherry-pick <a>^..<b>

Copy a range of commits onto the current branch

History

git show <commit>

View one commit in full detail

git log --author="name"

Filter history by author

git log --since="date" --until="date"

Filter history by date range

git log -5 --oneline

Show the last five commits, compactly

git revert <commit>

Safely undo a commit

git reset --hard <commit>

Rewrite history; use with caution