git cheat.sh

Intermediate · Workflow

Every command.
In workflow order.

A quick-reference for intermediate Git users — from cloning to shipping. Click any command to copy it.

No commands match ""
01

Setup & Config

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

Set the name attached to all your commits globally.

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

Set the email address associated with your commits.

git config --global core.editor "code --wait"

Set VS Code as the default editor for commit messages and merges.

git config --list

List all current Git configuration settings and their values.

git config --global alias.st status

Create a shortcut alias — e.g. type git st instead of git status.

git config --global init.defaultBranch main

Set the default branch name for all new repositories to main.

02

Getting a Repo

5 commands
git init

Initialize a new Git repository in the current directory.

git init <directory>

Create a new Git repository inside the named folder.

git clone <url>

Clone a remote repository into a new local directory.

git clone <url> <directory>

Clone into a specific folder name instead of the repo name.

git clone --depth 1 <url>

Shallow clone — only the latest snapshot, no full history. Faster for large repos.

03

Staging & Snapshots

9 commands
git status

Show the state of the working tree — staged, unstaged, and untracked files.

git add <file>

Stage a specific file for the next commit.

git add .

Stage all changes in the current directory and below.

git add -p

Interactively stage individual hunks of changes — great for clean, atomic commits.

git diff

Show unstaged changes between your working tree and the index.

git diff --staged

Show changes that are staged and ready to be committed.

git commit -m "message"

Commit staged changes with an inline message.

git commit --amend

Replace the last commit with a new one — useful for fixing typos or adding forgotten files.

git rm --cached <file>

Untrack a file without deleting it from disk — ideal for removing accidentally committed files.

04

Branching & Merging

10 commands
git branch

List all local branches. The current branch is marked with an asterisk.

git branch <name>

Create a new branch without switching to it.

git switch <branch>

Switch to an existing branch. Modern replacement for git checkout <branch>.

git switch -c <name>

Create a new branch and switch to it immediately.

git branch -d <name>

Delete a branch that has already been merged. Use -D to force-delete unmerged branches.

git merge <branch>

Merge the specified branch into the current branch.

git merge --no-ff <branch>

Merge and always create a merge commit — preserves branch history in the log.

git rebase <branch>

Reapply commits on top of another branch — produces a cleaner, linear history.

git rebase -i HEAD~<n>

Interactive rebase — squash, reorder, or edit the last n commits before pushing.

git cherry-pick <commit>

Apply a specific commit from another branch onto the current branch.

05

Remote Work

8 commands
git remote -v

List all configured remotes with their fetch and push URLs.

git remote add <name> <url>

Connect a new remote repository under a given name (typically origin).

git remote remove <name>

Remove a remote connection by name.

git fetch <remote>

Download all changes from the remote without merging into your working branch.

git pull

Fetch and immediately merge remote changes into the current branch.

git pull --rebase

Fetch and rebase local commits on top of remote changes — avoids unnecessary merge commits.

git push <remote> <branch>

Push a local branch up to the remote repository.

git push --force-with-lease

Safer force-push — only overwrites if no one else has pushed since your last fetch.

06

Inspecting History

8 commands
git log

Show the full commit history for the current branch.

git log --oneline --graph --all

Compact visual graph of all branches and their commit history.

git log --author="name" --since="2 weeks ago"

Filter commits by author and date range.

git show <commit>

Display the full diff and metadata of a specific commit.

git blame <file>

Show which commit and author last modified each line of a file.

git diff <branch1>..<branch2>

Show the diff between the tips of two branches.

git shortlog -sn

Summary of commit counts per author, sorted by most commits.

git bisect start

Begin a binary search through history to find the commit that introduced a bug.

07

Undoing Things

9 commands
git restore <file>

Discard unstaged changes in a file, restoring it to the last commit state.

git restore --staged <file>

Unstage a file without discarding its changes in the working tree.

git reset --soft HEAD~1

Undo the last commit but keep changes staged and ready to recommit.

git reset --mixed HEAD~1

Undo the last commit and unstage changes — files are still modified in the working tree.

git reset --hard HEAD~1

⚠️ Permanently discard the last commit and all its changes. Cannot be undone easily.

git revert <commit>

Create a new commit that undoes a previous commit — safe for shared/public branches.

git stash

Temporarily shelve uncommitted changes so you can switch context cleanly.

git stash pop

Re-apply the most recently stashed changes and remove them from the stash list.

git stash list

View all stashed change sets with their index and description.

08

Tagging & Releases

5 commands
git tag

List all tags in the repository.

git tag <name>

Create a lightweight tag pointing to the current commit.

git tag -a <name> -m "message"

Create an annotated tag with a message — recommended for release versions.

git push <remote> <tag>

Push a specific tag to the remote — tags are not pushed automatically.

git push <remote> --tags

Push all local tags to the remote at once.