Git 命令速查表与生成器
免费在线 Git 速查表,90+ 命令和示例,支持关键词搜索和分类浏览。
Showing 92 commands
git config --global user.name "Your Name"
Set global username
Example:
git config --global user.name "John Doe"
Flags: --global
git config --global user.email "email@example.com"
Set global email
Example:
git config --global user.email "john@example.com"
Flags: --global
git init
Initialize a new git repository
Example:
git init my-project
git clone <repo-url>
Clone a repository
Example:
git clone https://github.com/user/repo.git
git clone --depth 1 <repo-url>
Clone with limited history (shallow clone)
Example:
git clone --depth 1 https://github.com/user/repo.git
Flags: --depth
git branch
List local branches
Example:
git branch
git branch -a
List all branches (local and remote)
Example:
git branch -a
Flags: -a
git branch <branch-name>
Create a new branch
Example:
git branch feature/new-feature
git checkout -b <branch-name>
Create and switch to new branch
Example:
git checkout -b feature/new-feature
Flags: -b
git switch -c <branch-name>
Create and switch to new branch (modern)
Example:
git switch -c feature/new-feature
Flags: -c
git checkout <branch-name>
Switch to an existing branch
Example:
git checkout main
git switch <branch-name>
Switch to branch (modern syntax)
Example:
git switch main
git branch -d <branch-name>
Delete a branch
Example:
git branch -d feature/old-feature
Flags: -d
git branch -D <branch-name>
Force delete a branch
Example:
git branch -D feature/old-feature
Flags: -D
git branch -m <old-name> <new-name>
Rename a branch
Example:
git branch -m old-feature new-feature
Flags: -m
git branch -m <new-name>
Rename current branch
Example:
git branch -m renamed-feature
Flags: -m
git status
Show working tree status
Example:
git status
git add <file>
Stage a specific file
Example:
git add src/index.js
git add .
Stage all changes
Example:
git add .
git add -A
Stage all changes including deletions
Example:
git add -A
Flags: -A
git add -p
Interactive staging (patch mode)
Example:
git add -p
Flags: -p
git commit -m "message"
Commit with message
Example:
git commit -m "Add new feature"
Flags: -m
git commit -am "message"
Stage tracked files and commit
Example:
git commit -am "Update documentation"
Flags: -am
git commit --amend
Modify the last commit
Example:
git commit --amend
Flags: --amend
git commit --amend --no-edit
Amend last commit without changing message
Example:
git commit --amend --no-edit
Flags: --amend --no-edit
git commit --allow-empty -m "message"
Create empty commit
Example:
git commit --allow-empty -m "Trigger CI/CD"
Flags: --allow-empty
git stash
Stash current changes
Example:
git stash
git stash save "message"
Stash with description
Example:
git stash save "WIP: feature development"
git stash list
List all stashes
Example:
git stash list
git stash pop
Apply and remove last stash
Example:
git stash pop
git stash apply
Apply last stash without removing
Example:
git stash apply
git stash apply stash@{n}
Apply specific stash by index
Example:
git stash apply stash@{2}
git stash drop
Delete last stash
Example:
git stash drop
git stash clear
Delete all stashes
Example:
git stash clear
git merge <branch-name>
Merge branch into current branch
Example:
git merge feature/new-feature
git merge --no-ff <branch-name>
Merge with merge commit
Example:
git merge --no-ff feature/new-feature
Flags: --no-ff
git merge --squash <branch-name>
Squash and merge
Example:
git merge --squash feature/new-feature
Flags: --squash
git merge --abort
Abort merge in progress
Example:
git merge --abort
Flags: --abort
git rebase <branch-name>
Rebase current branch
Example:
git rebase main
git rebase -i HEAD~n
Interactive rebase last n commits
Example:
git rebase -i HEAD~3
Flags: -i
git rebase --abort
Abort rebase
Example:
git rebase --abort
Flags: --abort
git rebase --continue
Continue rebase after resolving conflicts
Example:
git rebase --continue
Flags: --continue
git remote
List remote repositories
Example:
git remote
git remote -v
List remotes with URLs
Example:
git remote -v
Flags: -v
git remote add <name> <url>
Add a new remote
Example:
git remote add origin https://github.com/user/repo.git
git remote remove <name>
Remove a remote
Example:
git remote remove old-remote
git remote rename <old> <new>
Rename a remote
Example:
git remote rename origin upstream
git remote set-url <name> <url>
Change remote URL
Example:
git remote set-url origin https://github.com/user/new-repo.git
git fetch
Fetch updates from remote
Example:
git fetch origin
git fetch --all
Fetch from all remotes
Example:
git fetch --all
Flags: --all
git pull
Fetch and merge remote changes
Example:
git pull origin main
git pull --rebase
Fetch and rebase instead of merge
Example:
git pull --rebase origin main
Flags: --rebase
git push
Push commits to remote
Example:
git push origin main
git push -u origin <branch>
Push and set upstream branch
Example:
git push -u origin feature/new-feature
Flags: -u
git push --all
Push all branches
Example:
git push --all origin
Flags: --all
git push --force
Force push (use with caution)
Example:
git push --force origin main
Flags: --force
git push --force-with-lease
Safer force push
Example:
git push --force-with-lease origin main
Flags: --force-with-lease
git push origin --delete <branch>
Delete remote branch
Example:
git push origin --delete feature/old-feature
Flags: --delete
git restore <file>
Discard changes in working directory
Example:
git restore src/index.js
git checkout -- <file>
Discard changes (older syntax)
Example:
git checkout -- src/index.js
Flags: --
git clean -fd
Remove untracked files and directories
Example:
git clean -fd
Flags: -fd
git reset <file>
Unstage a file
Example:
git reset src/index.js
git reset --soft HEAD~1
Undo last commit, keep changes staged
Example:
git reset --soft HEAD~1
Flags: --soft
git reset --mixed HEAD~1
Undo last commit, keep changes unstaged
Example:
git reset --mixed HEAD~1
Flags: --mixed
git reset --hard HEAD~1
Undo last commit and discard changes
Example:
git reset --hard HEAD~1
Flags: --hard
git revert <commit-hash>
Create new commit that undoes changes
Example:
git revert abc1234
git revert HEAD
Revert the last commit
Example:
git revert HEAD
git log
Show commit history
Example:
git log
git log --oneline
Show condensed commit history
Example:
git log --oneline
Flags: --oneline
git log --graph --all --oneline
Show visual branch history
Example:
git log --graph --all --oneline
Flags: --graph --all
git log -n <number>
Show last n commits
Example:
git log -n 10
Flags: -n
git log --author="name"
Show commits by specific author
Example:
git log --author="John"
Flags: --author
git log --grep="pattern"
Search commits by message
Example:
git log --grep="bug fix"
Flags: --grep
git log <file>
Show history for specific file
Example:
git log src/index.js
git show <commit-hash>
Show specific commit details
Example:
git show abc1234
git diff
Show unstaged changes
Example:
git diff
git diff --staged
Show staged changes
Example:
git diff --staged
Flags: --staged
git diff <branch1> <branch2>
Compare two branches
Example:
git diff main feature/new-feature
git blame <file>
Show line-by-line commit history
Example:
git blame src/index.js
git tag
List tags
Example:
git tag
git tag <tag-name>
Create a tag
Example:
git tag v1.0.0
git tag -a <tag-name> -m "message"
Create annotated tag
Example:
git tag -a v1.0.0 -m "Release 1.0"
Flags: -a
git cherry-pick <commit-hash>
Apply specific commit to current branch
Example:
git cherry-pick abc1234
git cherry-pick <commit1>..<commit2>
Cherry-pick range of commits
Example:
git cherry-pick abc1234..def5678
git bisect start
Start binary search for bug
Example:
git bisect start
git bisect bad
Mark current commit as bad
Example:
git bisect bad
git bisect good <commit-hash>
Mark commit as good
Example:
git bisect good abc1234
git reflog
Show reference logs
Example:
git reflog
git fsck --lost-found
Find lost commits
Example:
git fsck --lost-found
Flags: --lost-found
git hook
Manage git hooks
Example:
git hook list
git worktree add <path> <branch>
Create separate working tree
Example:
git worktree add ../hotfix main
git submodule add <url> <path>
Add a submodule
Example:
git submodule add https://github.com/user/module.git modules/dep
About Git Command Generator
Git is a distributed version control system used by millions of developers worldwide. This comprehensive guide provides quick access to over 60 essential Git commands organized by workflow category. Whether you're setting up your repository, managing branches, committing changes, or resolving conflicts, you'll find the command you need with explanations and practical examples.
Key Features
- Search functionality to quickly find commands by keyword
- Commands organized by workflow category for easy navigation
- Real-world examples for each command
- One-click copy functionality for fast command usage
Common Git Workflows
- Setup & Configuration: Initialize repositories and configure user information
- Branching Strategy: Create, switch, and manage feature branches
- Committing Changes: Stage files, commit with meaningful messages, and amend commits
- Remote Collaboration: Push, pull, and manage remote repositories
- Merging & Rebasing: Integrate branches and maintain clean history
- Undoing Changes: Revert commits, reset changes, and recover lost work