Version Control

Git Cheatsheet Pro

100+ essential commands. Searchable, categorized & copy-ready.

Showing 97 commands
Basics
git init

Initialize a new Git repository

Basics
git clone [url]

Clone a repository into a new directory

Basics
git status

Show modified files in working directory

Basics
git add .

Add all file changes to staging area

Basics
git add [file]

Add specific file to staging area

Basics
git commit -m '[msg]'

Commit all staged changes to local repo

Basics
git diff

Show unstaged changes

Basics
git diff --staged

Show staged changes

Basics
git remote -v

Show remote origins

Basics
git remote add origin [url]

Add a remote repository

Branching
git branch

List all local branches

Branching
git branch -a

List all branches (local & remote)

Branching
git branch [name]

Create a new branch

Branching
git checkout [branch]

Switch to specified branch

Branching
git checkout -b [branch]

Create a new branch and switch to it

Branching
git merge [branch]

Merge specified branch into current branch

Branching
git branch -d [branch]

Delete a local branch (safe)

Branching
git branch -D [branch]

Force delete a local branch

Branching
git push origin --delete [branch]

Delete a remote branch

Syncing
git push origin [branch]

Push local commits to remote repository

Syncing
git push -u origin [branch]

Push and set upstream branch

Syncing
git push --force

Force push (overwrites remote)

Syncing
git pull

Fetch and merge changes from remote

Syncing
git pull --rebase

Fetch and rebase instead of merge

Syncing
git fetch

Download objects and refs from remote

Syncing
git fetch --all

Fetch all remotes

Stashing
git stash

Temporarily store modified, tracked files

Stashing
git stash save '[message]'

Stash with a description

Stashing
git stash list

List all stashed changesets

Stashing
git stash pop

Restore the most recently stashed files

Stashing
git stash apply

Apply stash without removing it

Stashing
git stash apply stash@{n}

Apply a specific stash

Stashing
git stash drop

Delete the most recent stash

Stashing
git stash clear

Delete all stashes

History
git log

Show commit history

History
git log --oneline

Show commit history in single lines

History
git log --graph

Show commit history with ASCII graph

History
git log --oneline --graph --all

Visualize all branch history

History
git log -p [file]

Show changes over time for specific file

History
git log --author='[name]'

Show commits by specific author

History
git log --since='2 weeks ago'

Show commits from last 2 weeks

History
git blame [file]

Show who changed what and when in file

History
git show [commit]

Show details of specific commit

History
git reflog

Show a log of changes to HEAD

Undoing
git checkout -- [file]

Discard changes to a file

Undoing
git restore [file]

Restore file to last commit (Git 2.23+)

Undoing
git reset [file]

Unstage a file while retaining changes

Undoing
git reset --soft HEAD~1

Undo last commit, keep changes staged

Undoing
git reset --mixed HEAD~1

Undo last commit, keep changes unstaged

Undoing
git reset --hard HEAD~1

Undo last commit and delete changes

Undoing
git reset --hard [commit]

Reset to specific commit (destroys history)

Undoing
git revert [commit]

Create new commit that undoes changes

Undoing
git clean -fd

Remove untracked files and directories

Undoing
git clean -fdn

Preview what will be deleted

Tagging
git tag

List all tags

Tagging
git tag [name]

Create a lightweight tag

Tagging
git tag -a [name] -m '[msg]'

Create an annotated tag

Tagging
git push origin [tagname]

Push a tag to remote

Tagging
git push origin --tags

Push all tags to remote

Tagging
git tag -d [name]

Delete a local tag

Tagging
git push origin :refs/tags/[name]

Delete a remote tag

Advanced
git rebase [branch]

Reapply commits on top of another base tip

Advanced
git rebase -i HEAD~[n]

Interactive rebase last n commits

Advanced
git cherry-pick [commit]

Apply changes from specific commit

Advanced
git bisect start

Start binary search for bad commit

Advanced
git bisect bad

Mark current commit as bad

Advanced
git bisect good [commit]

Mark commit as good

Advanced
git bisect reset

End bisect session

Advanced
git worktree add [path] [branch]

Create a linked working tree

Advanced
git worktree list

List all working trees

Advanced
git worktree remove [path]

Remove a working tree

Advanced
git archive --format=zip HEAD > [file.zip]

Create zip of repository

Configuration
git config --global user.name '[name]'

Set author name globally

Configuration
git config --global user.email '[email]'

Set author email globally

Configuration
git config --list

List all settings

Configuration
git config --global alias.[alias] [command]

Create command shortcut

Configuration
git config --global core.editor '[editor]'

Set default editor

Configuration
git config --global color.ui auto

Enable helpful colorization

Submodules
git submodule add [url] [path]

Add a submodule

Submodules
git submodule init

Initialize submodules

Submodules
git submodule update

Update submodules

Submodules
git submodule update --remote

Update submodules to latest commit

Submodules
git submodule foreach git pull origin main

Pull all submodules

Troubleshooting
git fsck

Verify database integrity

Troubleshooting
git gc

Clean up unnecessary files and optimize repo

Troubleshooting
git prune

Remove unreachable objects

Troubleshooting
git remote prune origin

Remove stale remote branches

Troubleshooting
git reflog expire --expire=now --all

Clear reflog immediately

Troubleshooting
git ls-files

Show tracked files

Troubleshooting
git ls-files --others

Show untracked files

Git Flow
git flow init

Initialize git flow

Git Flow
git flow feature start [name]

Start a new feature branch

Git Flow
git flow feature finish [name]

Finish a feature branch

Git Flow
git flow release start [version]

Start a release branch

Git Flow
git flow release finish [version]

Finish a release branch

Git Flow
git flow hotfix start [name]

Start a hotfix branch

Git Flow
git flow hotfix finish [name]

Finish a hotfix branch

Enjoying Git Command Cheat Sheet? 🚀

WebGati provides this tool for free. Help us keep it alive by sharing it with your network!

Available for Hire

Need a Custom Tool like this for your Business?

I build high-performance web apps, AI tools, and SaaS platforms. Let's build your next big idea.

Start a Project