Git Cheat Sheet for Common Commands

Look up common Git commands.

Git

Config

git config --global user.name "Your Name"

Set username

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

Set email

git config --list

List config

Basics

git init

Initialize repo

git clone <url>

Clone repo

git add <file>

Stage file

git add .

Stage all

git commit -m "message"

Commit

git status

Status

git diff

Unstaged changes

Branch

git branch

List branches

git branch <name>

Create branch

git checkout <branch>

Switch branch

git checkout -b <branch>

Create and switch

git merge <branch>

Merge branch

git branch -d <branch>

Delete branch

Remote

git remote -v

List remotes

git push origin <branch>

Push

git pull origin <branch>

Pull

git fetch

Fetch

git remote add origin <url>

Add remote

Undo

git reset --soft HEAD~1

Undo last commit (keep changes)

git reset --hard HEAD~1

Undo last commit (discard)

git checkout -- <file>

Discard working tree changes

git stash

Stash

git stash pop

Pop stash

Log & Diff

git log

Commit history

git log --oneline

Short history

git show <commit>

Show commit

git diff <branch1> <branch2>

Compare branches

How to use it

  1. Search by a Git command or task such as branch or fetch.
  2. Read the matching command and its short description.
  3. Copy it and replace placeholders before running it in your own repository.

Common questions

Does this tool run Git commands?
No. It is a reference. Pasting and running a command in your terminal is a separate action.
What should I check before a reset?
Run git status and verify the branch and uncommitted work. Some reset modes discard work.

The tool processes your input in this browser. It does not upload the input itself.