Git Command Reference

Searchable Git command reference with 50+ commands organized by category. Find the right git command instantly with fuzzy search and one-click copy.

Showing 56 commands

Setup

Initialize a new Git repository

git init

Clone a remote repository

git clone <url>

Set your name for commits

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

Set your email for commits

git config --global user.email "[email protected]"

List all Git configuration

git config --list

Basics

Show working tree status

git status

Stage a specific file

git add <file>

Stage all changes

git add -A

Commit staged changes with a message

git commit -m "your message"

Amend the last commit (message or files)

git commit --amend

Show unstaged changes

git diff

Show staged changes

git diff --staged

Show commit history

git log --oneline --graph

Show commit history for a specific file

git log --follow <file>

Branching

List all local branches

git branch

List all branches (local + remote)

git branch -a

Create a new branch

git branch <name>

Switch to a branch

git checkout <branch>

Create and switch to a new branch

git checkout -b <name>

Delete a merged branch

git branch -d <name>

Force delete an unmerged branchDestructive

git branch -D <name>

Rename the current branch

git branch -m <new-name>

Merging

Merge a branch into the current branch

git merge <branch>

Merge with a merge commit (no fast-forward)

git merge --no-ff <branch>

Abort a merge in progress

git merge --abort

Rebase current branch onto another

git rebase <branch>

Abort a rebase in progress

git rebase --abort

Apply a specific commit to the current branch

git cherry-pick <commit-hash>

Remote

List remote repositories

git remote -v

Add a remote repository

git remote add <name> <url>

Download objects from remote (without merging)

git fetch origin

Fetch and merge from remote

git pull origin <branch>

Push commits to remote

git push origin <branch>

Push and set upstream tracking branch

git push -u origin <branch>

Force push (overwrites remote history)Destructive

git push --force-with-lease

Undoing

Discard changes to a file (unstaged)

git restore <file>

Unstage a file (keep changes)

git restore --staged <file>

Undo last commit, keep changes staged

git reset --soft HEAD~1

Undo last commit, keep changes unstaged

git reset HEAD~1

Undo last commit and discard all changesDestructive

git reset --hard HEAD~1

Create a new commit that undoes a previous commit

git revert <commit-hash>

Remove untracked filesDestructive

git clean -fd

Stashing

Stash current changes

git stash

Stash with a descriptive message

git stash push -m "message"

List all stashes

git stash list

Apply and remove the latest stash

git stash pop

Apply a stash without removing it

git stash apply stash@{0}

Delete a specific stash

git stash drop stash@{0}

Inspection

Show details of a commit

git show <commit-hash>

Show who changed each line of a file

git blame <file>

Show history of HEAD changes (recovery tool)

git reflog

Summarize commits by author

git shortlog -sn

Tags

List all tags

git tag

Create an annotated tag

git tag -a v1.0.0 -m "Release 1.0.0"

Push tags to remote

git push origin --tags

Delete a local tag

git tag -d <tag-name>

What the Git command reference does

Git has hundreds of commands and flags, and nobody remembers all of them. This searchable reference covers 50+ of the ones you actually reach for — organised by category, with fuzzy search so you can find "undo last commit" or "discard changes" by describing what you want, and one-click copy to grab the exact command.

How to find a command

  1. Search by intent ("stash", "rebase", "amend") or browse by category.
  2. Read what the command does before you run it.
  3. Copy it and adapt the placeholders to your branch or file.

The commands people forget

Everyday git is muscle memory; it's the rescue commands that slip — undoing the last commit without losing work (git reset --soft HEAD~1), discarding local changes to a file (git checkout -- file), un-staging (git restore --staged file), or recovering a lost commit with git reflog. Having them one search away turns a panic moment into a copy-paste.

Frequently asked questions

How do I undo the last commit?

git reset --soft HEAD~1 keeps your changes staged; --mixed unstages them; --hard discards them (careful).

How do I discard uncommitted changes?

git restore <file> (or git checkout -- <file> on older Git) reverts a file to the last commit.

How do I undo a pushed commit safely?

Use git revert <hash> — it creates a new commit that undoes the change, without rewriting shared history.

SharePost

More tools like this