Skip to content
Back to directory

Git Cheat Sheet

Git command references.

Need a faster backend? Get $200 on DigitalOcean.

Setup & Config

Set global user name

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

Set global user email

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

List all config settings

git config --list

Starting a Repo

Create local repo in current directory

git init

Clone a repository from URL

git clone [url]

Basic Workflow

Show modified files in working directory

git status

Add all modified files to staging

git add .

Commit staged files with a message

git commit -m "Message"

Show unstaged file differences

git diff

Branching & Merging

List all local branches

git branch

Create a new branch

git branch [branch-name]

Switch to a branch

git checkout [branch-name]

Merge [branch] into current branch

git merge [branch-name]

Rebase current branch onto [branch]

git rebase [branch-name]

Undoing & Rewriting

Modify the most recent commit

git commit --amend

Unstage a file (keep changes)

git reset HEAD [file]

Undo commit (keep local changes)

git reset --soft HEAD~1

Discard ALL local changes (caution!)

git reset --hard HEAD

Invert a commit (safe for shared history)

git revert [commit-id]

Reviewing History

Show full commit history

git log

Show history as a single-line graph

git log --oneline --graph --all

Show details of a specific commit

git show [commit-id]

See who changed which line in a file

git blame [file]

Remotes

List all remote URLs

git remote -v

Push current branch to remote

git push origin [branch]

Fetch and merge remote changes

git pull origin [branch]

Download remote changes (no merge)

git fetch origin

Stashing

Store uncommitted changes

git stash

Apply and remove latest stash

git stash pop

List all saved stashes

git stash list

Tagging

Create a new annotated tag

git tag -a v1.0 -m "Release v1.0"

Push all tags to remote server

git push origin --tags

Pro Tips

Apply specific commit to current branch

git cherry-pick [commit-id]

View history of Git operations (Reflog)

git reflog

Delete untracked files (careful!)

git clean -fd

How to Use the Git Cheat Sheet

01

Use the search bar to instantly filter commands by keyword, tag, or description (e.g., "rebase" or "undo").

02

Browse through logical categories like Basic Workflow, Branching, Remotes, and Pro Tips to find what you need.

03

Click the copy icon next to any snippet to instantly copy the exact Git command to your clipboard.

Features & Benefits

Instant Search

No more scrolling through endless documentation. Find the exact command you need instantly with real-time keyword filtering.

One-Click Copy

Avoid typos that could break your repository. Securely copy complex commands directly to your clipboard with a single click.

Categorized Workflow

Commands are neatly organized by the standard software development lifecycle, making it easy to follow along from setup to deployment.

Pro Tips Included

Go beyond the basics. Access advanced commands like git reflog, git cherry-pick, and deep resets to master version control.

Frequently Asked Questions

What is the difference between git fetch and git pull?

git fetch downloads updates from your remote repository to your local system but does not integrate them into your working files. git pull essentially runs a fetch and then immediately merges the downloaded changes into your current branch.

How do I safely undo my last commit?

If you haven't pushed yet, you can use git reset --soft HEAD~1 to undo the commit while keeping your changed files staged and ready to be modified. If you just need to change the commit message or add a forgotten file, use git commit --amend.

What does git stash do?

git stash takes your modified, uncommitted files and saves them away temporarily on a stack of unfinished changes. This allows you to switch branches or pull updates without having to commit half-done work. You can restore them later using git stash pop.

Ad
💻

DSAT Development 30% OFF

Professional website & software development at discounted price.

Get Offer