320 x 50 Mobile Ad
Cheat Sheets

Git Cheat Sheet

Transform, format, and optimize your data instantly with this free client-side tool.

Setup & Config

git config --global user.name 'Name'

Set global username

git config --global user.email 'email'

Set global email

git config --list

List all Git configurations

git init

Initialize a new Git repository

git clone <url>

Clone an existing repository

Basic Snapshot

git status

Show modified files in working directory

git add file.txt

Add file to staging area

git add .

Add all current changes to staging area

git commit -m 'message'

Commit staged changes

git commit -am 'message'

Add all tracked files and commit

git diff

Show unstaged changes

git diff --staged

Show staged changes

git restore file.txt

Discard changes in working directory

Branching & Merging

git branch

List all local branches

git branch -a

List local and remote branches

git branch <name>

Create new branch

git checkout <name>

Switch to branch

git checkout -b <name>

Create new branch and switch to it

git merge <branch>

Merge <branch> into current branch

git branch -d <name>

Delete local branch

git branch -D <name>

Force delete local branch

Sharing & Updating

git remote add origin <url>

Add remote repository

git remote -v

List remote connections

git fetch

Fetch remote history (does not merge)

git pull

Fetch and merge remote changes

git push

Push local commits to remote branch

git push -u origin <branch>

Push and set upstream tracking

git push origin --delete <branch>

Delete remote branch

Inspection & Comparison

git log

Show commit history

git log --oneline

Show condensed history

git log --graph

Show history with branch graph

git show <commit_id>

Show metadata and content changes of commit

git blame <file>

Show who changed what and when in a file

Undoing Changes

git revert <commit_id>

Create a new commit undoing changes from a previous commit

git reset --soft HEAD~1

Undo last commit, keep changes staged

git reset --hard HEAD~1

Undo last commit and DISCARD all changes

git clean -n

Dry run: show untracked files to be removed

git clean -fd

Remove untracked files and directories

Stashing

git stash

Temporarily store modified, tracked files

git stash push -m 'msg'

Stash changes with a message

git stash list

List all stashes

git stash apply

Restore most recent stash (keep in list)

git stash pop

Restore and remove most recent stash

git stash drop

Delete most recent stash

Advanced

git rebase <branch>

Reapply commits on top of another base tip

git rebase -i HEAD~3

Interactive rebase (squash, edit, reorder commits)

git cherry-pick <commit>

Apply changes from specific commit to current branch

git bisect start

Start binary search to find bug-introducing commit

git tag <name>

Create a lightweight tag

git push --tags

Push all tags to remote

git reflog

View local history of HEAD to recover lost commits

git commit --amend --no-edit

Add staged changes to the last commit without changing message

320 x 50 Mobile Ad

Frequently Asked Questions

Got questions? We've got answers.

The Git Cheatsheet is a quick-reference guide that provides developers with the most essential and frequently used Git commands, syntax, and snippets in one centralized place.
This reference is built for both beginners who are just learning Git and need a quick syntax lookup, as well as seasoned professionals who need to jog their memory on complex commands.
You can use the real-time search bar at the top of the cheatsheet. Simply type a keyword (like &#39;delete&#39; or &#39;file&#39;) and the list will instantly filter to show only matching Git commands.
Yes! Every command block features a one-click copy button. Just hover over the command and click the copy icon to instantly send the snippet to your clipboard.
The cheatsheet is divided into logical categories such as Basics, Network, Operations, and specific Git features. You can click on the category filters at the top to isolate specific groups of commands.
Absolutely. This Git reference guide is 100% free, requiring no sign-ups or subscriptions, and is always available when you need it.
While these are standard Git operations, you should always understand what a command does before running it, especially if it involves system operations or destructive actions.
Yes, we have recently expanded this cheatsheet to include advanced snippets, best practices, and edge-case syntax that go beyond basic introductory commands.
ADVERTISEMENT
Boost Your Business Online