---
title: "Git Cheatsheet common commands reference - AllTools"
description: "A quick-reference of high-frequency Git commands for commits, branching, merge/rebase, stash/undo and remote collaboration, each with a copyable example."
canonical_url: "https://tool.warmday.wang/en/dev/git-cheatsheet"
meta:
  author: AllTools
  keywords: "online tools, AllTools, free online tools, developer tools, image tools, PDF tools, text tools, unit converter, no login, browser-based tools"
  "og:description": "A quick-reference of high-frequency Git commands for commits, branching, merge/rebase, stash/undo and remote collaboration, each with a copyable example."
  "og:image": "https://tool.warmday.wang/img/og-cover.png"
  "og:image:alt": "AllTools Logo"
  "og:image:height": "630"
  "og:image:width": "1200"
  "og:title": "Git Cheatsheet common commands reference"
  "twitter:image": "https://tool.warmday.wang/img/og-cover.png"
---

> Index of every page on this site: [llms.txt](https://tool.warmday.wang/llms.txt)

# **Git Cheatsheet**

Git command reference organized by scenario for quick lookup.

**Search Commands**

## **Initialization & Config**

`git init`

Initialize a new Git repository in the current directory

`git clone <url>`

Clone remote repository to local

`git clone <url> <dir>`

Clone remote repository to specified directory

`git config --global user.name "名字"`

Set global username

`git config --global user.email "邮箱"`

Set global email

`git config --list`

View all configuration

`git config --global alias.co checkout`

Set command alias

## **Basic Operations**

`git status`

View working and staging area status

`git add <file>`

Add file to staging area

`git add .`

Add all changes to staging area

`git add -p`

Interactively select changes to stage

`git commit -m "消息"`

Commit staged changes

`git commit -am "消息"`

Add and commit tracked files

`git commit --amend`

Modify the most recent commit

`git commit --amend --no-edit`

Modify last commit without changing message

## **Branch Management**

`git branch`

List local branches

`git branch -a`

List all branches (including remote)

`git branch <name>`

Create new branch

`git branch -d <name>`

Delete merged branch

`git branch -D <name>`

Force delete branch

`git checkout <branch>`

Switch to specified branch

`git checkout -b <name>`

Create and switch to new branch

`git switch <branch>`

Switch branch (new command)

`git switch -c <name>`

Create and switch to new branch (new command)

`git merge <branch>`

Merge specified branch into current branch

`git merge --no-ff <branch>`

Non-fast-forward merge (preserve history)

`git rebase <branch>`

Rebase: rebase current branch onto target branch

`git rebase -i <commit>`

Interactive rebase

## **Remote Operations**

`git remote -v`

View remote repository info

`git remote add origin <url>`

Add remote repository

`git remote set-url origin <url>`

Change remote repository URL

`git fetch`

Fetch latest from remote (no merge)

`git fetch --all`

Fetch from all remotes

`git pull`

Pull remote changes and merge

`git pull --rebase`

Pull remote changes and rebase

`git push`

Push local commits to remote

`git push -u origin <branch>`

Push and set upstream branch

`git push origin --delete <branch>`

Delete remote branch

`git push --force`

Force push (use with caution)

## **View History**

`git log`

View commit history

`git log --oneline`

Compact view of commit history

`git log --graph --oneline`

Graphical view of branch/merge history

`git log -n <num>`

View last N commits

`git log --author="名字"`

Filter commits by author

`git log --since="2 weeks ago"`

Filter commits by time

`git log -p <file>`

View commit history and diff for file

`git blame <file>`

View last modification per line

`git diff`

View working area vs staging area diff

`git diff --staged`

View staging area vs last commit diff

`git diff <branch1> <branch2>`

View diff between two branches

`git show <commit>`

View detailed info for a commit

## **Undo & Revert**

`git restore <file>`

Undo working area changes (new command)

`git restore --staged <file>`

Unstage (new command)

`git checkout -- <file>`

Undo working area changes (old command)

`git reset HEAD <file>`

Unstage (old command)

`git reset --soft <commit>`

Reset to commit, keep changes in staging area

`git reset --mixed <commit>`

Reset to commit, keep changes in working area

`git reset --hard <commit>`

Reset to commit, discard all changes

`git revert <commit>`

Create new commit to revert specified commit

`git revert -n <commit>`

Revert without auto-commit

`git clean -fd`

Remove untracked files and directories

`git clean -fdn`

Preview untracked files to be deleted

## **Stash**

`git stash`

Stash current changes

`git stash save "描述"`

Stash with description

`git stash list`

List all stashes

`git stash pop`

Pop last stash and delete

`git stash apply`

Apply last stash without deleting

`git stash apply stash@{n}`

Apply specific stash

`git stash drop stash@{n}`

Drop specific stash

`git stash clear`

Delete all stashes

`git stash branch <name>`

Create branch from stash

## **Tag Management**

`git tag`

List all tags

`git tag <name>`

Create lightweight tag

`git tag -a <name> -m "消息"`

Create annotated tag

`git tag <name> <commit>`

Tag specific commit

`git tag -d <name>`

Delete local tag

`git push origin <tag>`

Push tag to remote

`git push origin --tags`

Push all tags to remote

`git push origin --delete tag <name>`

Delete remote tag

## **Advanced Operations**

`git cherry-pick <commit>`

Apply specific commit to current branch

`git cherry-pick <c1>..<c2>`

Apply multiple commits to current branch

`git reflog`

View all operations (for recovery)

`git bisect start`

Start bisect to locate bug

`git bisect good <commit>`

Mark good commit

`git bisect bad <commit>`

Mark bad commit

`git worktree add <dir> <branch>`

Create worktree (multi-branch work)

`git submodule add <url>`

Add submodule

`git submodule update --init`

Initialize and update submodules

### **Usage Guide**

#### **Command Categories**

This cheatsheet organizes Git commands into nine categories by scenario: Initialization & Config, Basic Operations, Branch Management, Remote Operations, History Viewing, Undo & Rollback, Stash & Storage, Tag Management, and Advanced Operations.

#### **Search Function**

The top search bar supports fuzzy matching by command text or description (based on Fuse.js). Entering keywords automatically filters categories containing matching commands; categories with no matches are hidden.

#### **Copy Commands**

!Hover over a command to reveal a copy button on the right. Click to copy the full command to clipboard; a toast notification appears on successful copy. Placeholders in angle brackets (e.g., \<file>, \<url>) need to be replaced with actual values.

## **Related tools**

More from the same category · Developer Tools

[**Cron Expression**Visual Cron builder: pick minute-hour-day-month-weekday fields and preview next run times live.](https://tool.warmday.wang/en/dev/cron) [**JSON Formatter**JSON beautify, minify and validate with auto error location for missing brackets and stray commas.](https://tool.warmday.wang/en/dev/json) [**Timestamp Converter**Convert Unix timestamps to dates and back with second/millisecond precision and live current time.](https://tool.warmday.wang/en/dev/timestamp) [**Regex Tester**Test regex with live match highlighting, capture groups and substitution, toggling g/i/m/s flags.](https://tool.warmday.wang/en/dev/regex) [**JWT Parser**Split a JWT into header, payload and signature, then base64url-decode claims and expiry without a key.](https://tool.warmday.wang/en/dev/jwt-parser) [**JWT Generator**Issue JWTs with custom header, claims and expiry across HS256, RS256, ES256 for auth-flow testing.](https://tool.warmday.wang/en/dev/jwt-generator)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://tool.warmday.wang/#organization","name":"AllTools","alternateName":"AllTools - 全能工具箱","url":"https://tool.warmday.wang/","logo":{"@type":"ImageObject","url":"https://tool.warmday.wang/img/logo.png","width":512,"height":512}},{"@type":"WebSite","@id":"https://tool.warmday.wang/en#website","url":"https://tool.warmday.wang/en","name":"AllTools","inLanguage":"en","publisher":{"@id":"https://tool.warmday.wang/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://tool.warmday.wang/en?q={search_term_string}"},"query-input":"required name=search_term_string"}},{"@type":"WebPage","@id":"https://tool.warmday.wang/en/dev/git-cheatsheet#webpage","url":"https://tool.warmday.wang/en/dev/git-cheatsheet","isPartOf":{"@id":"https://tool.warmday.wang/en#website"},"inLanguage":"en","name":"Git Cheatsheet common commands reference","description":"A quick-reference of high-frequency Git commands for commits, branching, merge/rebase, stash/undo and remote collaboration, each with a copyable example."},{"@type":"SoftwareApplication","@id":"https://tool.warmday.wang/en/dev/git-cheatsheet#app","name":"Git Cheatsheet common commands reference","description":"A quick-reference of high-frequency Git commands for commits, branching, merge/rebase, stash/undo and remote collaboration, each with a copyable example.","url":"https://tool.warmday.wang/en/dev/git-cheatsheet","applicationCategory":"DeveloperApplication","operatingSystem":"Web","inLanguage":"en","isPartOf":{"@id":"https://tool.warmday.wang/en/dev/git-cheatsheet#webpage"},"offers":{"@type":"Offer","price":"0","priceCurrency":"CNY"}},{"@type":"BreadcrumbList","@id":"https://tool.warmday.wang/en/dev/git-cheatsheet#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://tool.warmday.wang/en"},{"@type":"ListItem","position":2,"name":"Developer Tools","item":"https://tool.warmday.wang/en/dev"},{"@type":"ListItem","position":3,"name":"Git Cheatsheet","item":"https://tool.warmday.wang/en/dev/git-cheatsheet"}]}]}
```

## Sitemap

See the full [sitemap](https://tool.warmday.wang/sitemap.md) for all pages.
