Changelog

Git Cheat Sheet

Git Common Commands Cheat Sheet, quickly find and copy Git commands

Configuration and Initialization
9
git init

Initialize a new Git repository in the current directory

git init --bare

Initialize a bare repository (no working directory, for servers)

git clone <url>

Clone a remote repository to local

git clone --depth 1 <url>

Shallow clone, only fetch the latest commit (saves time and space)

git clone -b <branch> <url>

Clone a specific branch

git config --global user.name "Name"

Set global username

git config --global user.email "Email"

Set global email

git config --list

View all configurations

git config --global core.editor vim

Set default editor

Basic Operations
15
git status

View working directory status

git status -s

View concise status

git add <file>

Add file to staging area

git add .

Add all changes to staging area

git add -p

Interactive add, allows selecting parts of changes

git commit -m "Commit message"

Commit staged changes

git commit --amend

Amend the last commit

git commit --amend --no-edit

Amend the last commit (without changing the commit message)

git commit -am "Commit message"

Add changes from all tracked files and commit

git diff

View differences between working directory and staging area

git diff --staged

View differences between staging area and last commit

git diff <commit1> <commit2>

Compare differences between two commits

git rm <file>

Delete file and record the deletion

git rm --cached <file>

Remove file from staging area, but keep it in the working directory

git mv <old> <new>

Move or rename file

Branch Management
13
git branch

List local branches

git branch -a

List all branches (including remote)

git branch -r

List remote branches

git branch <branch>

Create a new branch

git checkout <branch>

Switch to the specified branch

git checkout -b <branch>

Create and switch to a new branch

git switch <branch>

Switch branch (Git 2.23+)

git switch -c <branch>

Create and switch branch (Git 2.23+)

git branch -d <branch>

Delete a merged branch

git branch -D <branch>

Force delete branch

git branch -m <old> <new>

Rename branch

git branch -u origin/<branch>

Set upstream branch for the current branch

git branch -vv

View branch details (including upstream branch)

Remote Repositories
17
git remote -v

View list of remote repositories

git remote add <name> <url>

Add a remote repository

git remote remove <name>

Remove a remote repository

git remote rename <old> <new>

Rename a remote repository

git remote show <name>

View remote repository details

git remote set-url <name> <url>

Modify remote repository URL

git fetch <remote>

Fetch updates from remote repository

git fetch --all

Fetch updates from all remote repositories

git fetch -p

Fetch updates and prune deleted remote branches

git pull

Pull and merge remote branches

git pull --rebase

Pull and rebase

git push

Push to remote repository

git push -u origin <branch>

Push and set upstream branch

git push --force

Force push (use with caution)

git push --force-with-lease

Safe force push

git push --tags

Push all tags

git push origin --delete <branch>

Delete remote branch

Undoing and Reverting
12
git restore <file>

Discard changes in the working directory (Git 2.23+)

git restore --staged <file>

Unstage (Git 2.23+)

git checkout -- <file>

Discard changes in the working directory (old way)

git reset --soft HEAD~1

Undo the last commit, keeping changes in the staging area

git reset HEAD~1

Undo the last commit, keeping changes in the working directory

git reset --hard HEAD~1

Undo the last commit, discarding all changes

git reset HEAD <file>

Unstage specified file

git reset --hard <commit>

Reset to a specific commit

git revert <commit>

Create a new commit to undo a specific commit

git revert -n <commit>

Undo commit without auto-committing

git clean -fd

Delete untracked files and directories

git clean -nd

Preview untracked files to be deleted

Staging Operations
12
git stash

Stash current changes

git stash save "description message"

Stash and add description

git stash -u

Stash including untracked files

git stash list

View stash list

git stash pop

Restore the most recent stash and delete it

git stash apply

Restore the most recent stash but do not delete it

git stash apply stash@{n}

Restore a specific stash

git stash drop

Delete the most recent stash

git stash drop stash@{n}

Delete a specific stash

git stash clear

Clear all stashes

git stash show -p

View detailed contents of a stash

git stash branch <branch>

Create a new branch from a stash

Viewing Logs
14
git log

View commit history

git log --oneline

Display commit history in a single line

git log --oneline --graph

Display commit history graphically

git log --oneline --graph --all

Display commit history of all branches

git log -n <number>

Display the last n commits

git log --author="name"

Filter commits by author

git log --since="2024-01-01"

Filter commits by date

git log --grep="keyword"

Search by commit message

git log -- <file>

View commit history of a specific file

git log --stat

Show file change statistics for each commit

git log -p

Show detailed diff for each commit

git reflog

View all operation records (including deleted commits)

git show <commit>

View details of a specific commit

git shortlog -sn

Count commits by author

Tag Management
10
git tag

List all tags

git tag -l "v1.*"

List tags by pattern

git tag <tagname>

Create a lightweight tag

git tag -a <tagname> -m "Description"

Create an annotated tag

git tag <tagname> <commit>

Create a tag for a specific commit

git show <tagname>

View tag details

git tag -d <tagname>

Delete a local tag

git push origin <tagname>

Push a single tag

git push origin --tags

Push all tags

git push origin --delete <tagname>

Delete a remote tag

Merging and Rebasing
10
git merge <branch>

Merge the specified branch into the current branch

git merge --no-ff <branch>

Non-fast-forward merge, preserve branch history

git merge --squash <branch>

Squash merge, combine all commits into one

git merge --abort

Abort merge

git rebase <branch>

Rebase the current branch onto the specified branch

git rebase -i HEAD~n

Interactively rebase the last n commits

git rebase --continue

Continue rebase

git rebase --abort

Abort rebase

git cherry-pick <commit>

Apply the specified commit to the current branch

git cherry-pick -n <commit>

Apply commit but do not auto-commit

Advanced Operations
13
git bisect start

Start a binary search (to locate problematic commit)

git bisect bad

Mark the current commit as bad

git bisect good <commit>

Mark the specified commit as good

git bisect reset

End binary search

git blame <file>

View the last modifier of each line in a file

git blame -L 10,20 <file>

View the modifier of a specified line range

git worktree add <path> <branch>

Create a new worktree

git worktree list

List all worktrees

git submodule add <url> <path>

Add a submodule

git submodule update --init --recursive

Initialize and update all submodules

git archive --format=zip HEAD > archive.zip

Package the repository as a zip file

git gc

Clean up and optimize the repository

git fsck

Check repository integrity

πŸ“–Tool Introduction

Git Cheat Sheet is a quick reference tool for Git commands, designed specifically for developers. It covers all common commands from basic operations to advanced techniques, organized by function, and supports quick search and one-click copy. Whether you are a Git novice or an experienced developer, you can quickly find the commands you need here. All commands are accompanied by clear Chinese explanations to help you better understand and use Git.

Key Features

1
10+ categories, covering all common Git scenarios
2
100+ common commands, comprehensively collected from basic to advanced
3
Supports keyword search to quickly locate desired commands
4
One-click copy command to improve work efficiency
5
Clear Chinese explanations, easy to understand and learn
6
Browse and filter by category to quickly find related commands
7
Responsive design, supports mobile viewing
8
Runs locally, no internet required

❓Frequently Asked Questions

πŸ”—Related Tools

Cron Expression Parser

Validate cron syntax and preview upcoming schedules.

Developer Tools
Try Now

JSON to CSV

Convert JSON data to CSV format

Converters
Try Now

JSON to YAML

Convert JSON data to YAML format

Converters
Try Now

JSON to XML

Convert JSON data to XML format

Converters
Try Now

YAML to JSON

Convert YAML configuration to JSON data

Converters
Try Now

JSON Formatter

Format, validate and minify JSON data

JSON Utilities
Try Now

JSON Visualizer

Display JSON data in tree structure

JSON Utilities
Try Now

JSON Data Generator

Generate mock JSON data for testing

JSON Utilities
Try Now

i18n JSON Translator

Translate entire JSON locale files in one go. Paste your base content, choose target languages, and the tool will call your OpenRouter-powered API with flattened keys.

JSON Utilities
Try Now

JSON Diff Comparison

Compare differences between two JSON data

JSON Utilities
Try Now

QR Code Generator

Generate custom QR code images

Image Tools
Try Now

SVG Placeholder Generator

Generate custom SVG placeholder images

Image Tools
Try Now

Base64 Image Converter

Convert images to Base64 encoding and vice versa

Image Tools
Try Now

UUID Generator

Generate UUID unique identifiers in batch

Generator Tools
Try Now

Password Generator

Generate secure and reliable random passwords

Generator Tools
Try Now

Base64 Encoder/Decoder

Base64 string encoding and decoding tool

Text Tools
Try Now

URL Encoder/Decoder

URL string encoding and decoding tool

Text Tools
Try Now

MD5 Hash Generator

Generate MD5 hash values from text

Crypto Tools
Try Now

SHA256 Hash Generator

Generate SHA256 hash values from text

Crypto Tools
Try Now

SHA1 Hash Generator

Generate SHA1 hash values from text

Crypto Tools
Try Now

Hex Encoder/Decoder

Hexadecimal string encoding and decoding tool

Crypto Tools
Try Now

Binary Encoder/Decoder

Binary string encoding and decoding tool

Crypto Tools
Try Now

AES Encrypt/Decrypt

AES symmetric encryption algorithm tool

Crypto Tools
Try Now

RSA Encrypt/Decrypt

RSA asymmetric encryption algorithm tool

Crypto Tools
Try Now

HMAC Generator

HMAC message authentication code generation tool

Crypto Tools
Try Now

IP Address Lookup

Query geographical location and network information of IP addresses

Network Tools
Try Now

Milliseconds Time Converter

Convert between millisecond timestamps and formatted date strings.

Time Tools
Try Now
Showing 27 of 28 tools
    Git Cheat Sheet - Quick Reference for Common Commands - IT Tools Collection