Git Cheatsheet
A focused reference of the Git commands that come up in real work — not every flag, but the ones you actually use. Skim for what you need, or read through to fill the gaps.
Setup & config
Start a new repository in the current directory.
Copy a remote repository locally.
Set your commit author name.
Set your commit email.
Staging & committing
Show changed, staged and untracked files.
Stage a file; use . to stage everything.
Commit staged changes with a message.
Edit the most recent commit (message or contents).
Show unstaged changes; add --staged for staged.
Branching & merging
List branches; add -a to include remotes.
Create and switch to a new branch.
Switch to an existing branch.
Merge a branch into the current one.
Replay your commits on top of another branch.
Remotes
Fetch and merge changes from the remote.
Send your commits to the remote.
Push a new branch and track it.
Download remote changes without merging.
Undoing things
Discard unstaged changes to a file.
Unstage a file, keeping its changes.
Undo the last commit, keep changes staged.
Undo the last commit and discard changes.
Create a new commit that undoes a commit.
Stash & history
Shelve uncommitted changes temporarily.
Reapply the most recent stash.
Compact one-line commit history.
Visual branch and merge history.