coderef

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.

  • Set your name and email
  • Default branch name
  • Start a repo
  • Clone a repo
  • Ignore files

Saving changes

Stage and commit.

  • See what changed
  • Stage files
  • Unstage a file
  • Commit
  • Fix the last commit
  • See differences

Branches

Create, switch and clean up branches.

  • List branches
  • Create and switch
  • Switch branch
  • Rename current branch
  • Delete a branch
  • Delete a remote branch

Merging & rebasing

Bring work together.

  • 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.

  • List remotes
  • Add a remote
  • Download changes
  • Download and merge
  • Upload
  • Force push safely

Undoing things

Fix mistakes.

  • 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

History & tags

Inspect and label.

  • Log
  • Show a commit
  • Who changed a line
  • Search history for text
  • Tag a release
  • Push tags

← All quick references