Git Quick Reference
Git commands for setup, saving changes, branching, merging, remotes, undoing mistakes and inspecting history.
7 sections · 43 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Setup
Configure Git and start a repository.
TaskCode
- Set your name and email
- Default branch name
- Start a repo
- Clone a repo
- Ignore files
Saving changes
Stage and commit.
TaskCode
- See what changed
- Stage files
- Unstage a file
- Commit
- Fix the last commit
- See differences
Branches
Create, switch and clean up branches.
TaskCode
- List branches
- Create and switch
- Switch branch
- Rename current branch
- Delete a branch
- Delete a remote branch
Merging & rebasing
Bring work together.
TaskCode
- Merge a branch into the current one
- Merge with a merge commit
- Rebase onto main
- Interactive rebase (squash, reorder)
- Copy a commit
- Resolve a conflict
- Abort
Remotes
Share work with others.
TaskCode
- List remotes
- Add a remote
- Download changes
- Download and merge
- Upload
- Force push safely
Undoing things
Fix mistakes.
TaskCode
- Discard changes to a file
- Undo last commit, keep changes
- Undo last commit, discard changes
- Undo a pushed commit safely
- Stash work in progress
- Remove untracked files
- Find a lost commit