Introducing the list of commonly used Git commands

1. Quick check of common Git commands
git branch View all local branches
git status View the current status
git commit Submit
git branch -a View all branches
git branch -r View all remote branches
git commit -am "init" Submit and add comments
git remote add origin git@192.168.1.119:ndshow
git push origin master Push the file to the server
git remote show origin Display the resources in the remote library origin
git push origin master:develop
git push origin master:hb-dev Compare the local library to the server Library association
git checkout --track origin/dev Switch to the remote dev branch
git branch -D master develop Delete the local library develop
git checkout -b dev Create a new local branch dev
git merge origin/dev Merge branch dev with the current branch
git checkout dev Switch to the local dev branch
git remote show View the remote library
git add .
git rm file name (including path) Delete the specified file from git
git clone git://github.com/schacon/grit.git Pull the code from the server
git config --list View all users
git ls-files View what has been submitted
git rm [file name] Delete a file
git commit -a Commit all changes to the current repos
git add [file name] Add a file to git index
git commit -v When you use the -v parameter, you can see the difference in commits
git commit -m "This is the message describing the commit" Add commit information
git commit -a -a represents add, adding all Add the change to the git index and then commit
git commit -a -v General commit command
git log Look at your commit log
git diff Check the updates that have not been staged
git rm a.a move Remove files (delete from the staging area and workspace)
git rm --cached a.a Remove files (only delete from the staging area)
git commit -m "remove" Remove files (from Git Delete)
git rm -f a.a forcefully remove the modified file (delete from the staging area and workspace)
git diff --cached or $ git diff --staged to view uncommitted updates
git stash push Push the file to a temporary space
git stash pop Pop the file from the temporary space
--------------------- ------------------------------------
git remote add origin git@github.com:username /Hello-World.git
git push origin master Submit the local project to the server
-------------------------- ----------------------------------
git pull local and server synchronization
---- -------------------------------------------------- -----------
git push (remote warehouse name) (branch name) Push the local branch to the server.
git push origin serverfix:awesomebranch
----------------------------------------- ----------------------------
git fetch is equivalent to getting the latest version from the remote to the local, and will not automatically merge
git commit -a -m "log_message" (-a is to submit all changes, -m is to add log information) Local changes are synchronized to the server:
git branch branch_0.1 master creates branch_0.1 branch from the main branch master
git branch -m branch_0.1 branch_1.0 Rename branch_0.1 to branch_1.0
git checkout branch_1.0/master Switch to branch_1.0/master branch
du -hs
git branch delete remote branch
git push origin :branch_remote_name
git branch -r -d branch_remote_name
---------------------- -------------------------------------
Initialize the version library and submit it to Remote server side
mkdir WebApp
cd WebApp
git init local initialization
touch README
git add README add file
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git
Add a remote server
The above command will add a remote server library with the URL address 'git@github.com:daixu/WebApp.git' and the name origin. When submitting code in the future, you only need to use the origin alias
Recommendation (free): Git
2. Git command cheat sheet
1. Commonly used Git commands
Command |
Brief description |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##git add |
Add to the staging area |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git add–interactive |
Interactive add |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ##git apply
| ##Apply patch|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
##Apply email format patch |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git annotate |
## Synonyms, equivalent to git blame |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git archive |
##File archive packaging
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git bisect
| ##Binary search|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git cherry-pick |
##Submit pick |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git citool |
##Graphical submission, equivalent to git gui Command |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git clean
| ##Clear untracked files in the workspace|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
##Clone repository |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##submit |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Query and modify configuration |
| git describe||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visually display commit IDs by milestone | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git diff |
##Difference comparison |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git difftool |
Calling the graphical difference comparison tool |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git fetch |
Get the commit of the remote repository |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git format-patch |
Create a patch file in email format. See git am Command |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ##git grep
|
file content Search positioning tool
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git gui
|
Based on Tcl/ Tk 's graphical tool, focusing on operations such as submission |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git help
| ##help|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git init |
##Repository initialization |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git init-db* |
## Synonyms, equivalent to git init
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git log
| ##Display commit log
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git push |
##Push to the remote repository |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git rebase |
##branch rebase
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git rebase–interactive
| ##Interactive branch rebase
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
## Branch and other reference change record management |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Remote repository management |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Synonyms, equivalent to git config |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Reset changed branch " | cursor" points to |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git rev-parse |
Convert various reference representations to hashes Value etc |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git revert |
Reverse commit |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##git rm |
Delete file |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git show |
##Display various types of objects
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git stage*
| ## Synonyms, equivalent to git add|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git tag |
##Milestone Management |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Commands |
A brief description |
git commit-tree |
Creates a commit from a tree object |
# #git hash-object |
Compute hash value or create object from standard input or file |
git ls-files |
Display workspace and staging area files |
git ls-tree |
Display the files contained in the tree object |
git mktag |
Read standard input to create a milestone object |
git mktree |
Read standard input to create a tree object |
git read-tree |
Read the tree object to the temporary storage area |
git update-index |
Register the workspace content to the staging area and manage the staging area |
git unpack-file |
Creates a temporary file containing the contents of the specified blob |
git write-tree |
Create a tree object from the staging area |
3. Reference operation related commands
Command |
Brief description |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##git check-ref-format |
Check whether the reference name conforms to the specification |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ##git for-each-ref
|
Reference iterator, for shell Programming | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git ls-remote
|
Display references to remote repositories
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git name-rev
|
Display commit ID as friendly name |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| git peek-remote*
|
Outdated commands, please use git ls-remote |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##git rev-list |
Show version range |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ##git show-branch
|
Display branch list and topological relationship
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Display or set symbol references |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Update reference point |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Verify GPG Signed Tag |
4. Commands related to repository management
7. Protocol related commands
8. Commands related to repository conversion and interaction
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The above is the detailed content of Introducing the list of commonly used Git commands. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
How do I clone an existing Git repository from a remote server?
Jun 24, 2025 am 12:05 AM
TocloneaGitrepository,ensureGitisinstalledbycheckingwithgit--versionandinstallingifneeded.(1)Setupyourusernameandemailusinggitconfig.(2)UsegitclonefollowedbytherepositoryURLtocreatealocalcopy.(3)Forprivaterepos,useSSHwithanaddedkey.(4)Optionallyspeci
What is the purpose of the .gitignore file?
Jun 22, 2025 am 12:11 AM
.gitignore files are used to specify files or folders that Git should ignore, preventing them from being committed to the repository, thus avoiding unnecessary or sensitive files being traced. Its core functions include: 1. Exclude temporary files generated during development such as node_modules, .env, .log, etc.; 2. Avoid specific files generated by the operating system or editor entering version control; 3. Clean up the compiled products generated by the construction tool such as dist/, build/ directory; 4. Pay attention to syntax such as wildcard characters *, directories ending with /, and ! when setting. If you have submitted the file, you need to manually run gitrm-r--cached. Clear the cache and then resubmit it.
How do I clear the entire stash list?
Jul 01, 2025 am 12:02 AM
To clear the entire stash list in Git, there are no direct built-in commands, but it can be done in a few steps. First run gitstashlist to view all current stash entries, and then use gitstashdropstash@{n} to delete them one by one, or use gitreflogdelete --expire-unreachable=nowrefs/stash and gitgc-prune=now to force all stashes to be cleared at once. In addition, you can also use the bash loop command whilegitstashlist|grep-q'^stash@';dogitstashdrop;d
What are Git submodules, and why are they used?
Jun 25, 2025 am 12:13 AM
Git submodule allows embedding of one Git repository as a subdirectory into another repository, suitable for references to external projects or components without merging their history. Reasons for using submodules include: managing third-party libraries with independent version control, maintaining independent development history for different parts of a project, and sharing code among multiple projects. The working principle of a submodule is: when adding a submodule, Git will record the specific submissions to be used, and the parent project only tracks the changes in the submodule, not the file changes in the submodule; the submodule needs to be initialized and updated after cloning the main repository; the submodule information is stored in the .gitmodules file and .git/config, and the actual file is located in the .git/modules/ path. Applicable scenarios include: Strict control of external dependency versions
How do I view the commit history of my Git repository?
Jul 13, 2025 am 12:07 AM
To view Git commit history, use the gitlog command. 1. The basic usage is gitlog, which can display the submission hash, author, date and submission information; 2. Use gitlog--oneline to obtain a concise view; 3. Filter by author or submission information through --author and --grep; 4. Add -p to view code changes, --stat to view change statistics; 5. Use --graph and --all to view branch history, or use visualization tools such as GitKraken and VSCode.
What are packfiles in Git?
Jul 08, 2025 am 12:14 AM
Packfile is an efficient mechanism used by Git to package, compress and transfer repository objects. When you execute gitpush, gitfetch or gitclone, what Git actually transmits is the packfile; 1. It is initially generated by loose objects through gitgc or gitrepack commands and stored in the .git/objects/pack/ directory; 2. The packfile not only contains object data, but also records the delta relationship between objects, and achieves rapid search with index file (.idx). 3. This design reduces the transmission volume and improves synchronization efficiency; 4. A large number of small packfiles may affect performance, and can be used through gitgc or git
How do I delete a Git branch?
Jul 13, 2025 am 12:02 AM
To delete a Git branch, first make sure it has been merged or no retention is required. Use gitbranch-d to delete the local merged branch. If you need to force delete unmerged branches, use the -D parameter. Remote branch deletion uses the gitpushorigin-deletebranch-name command, and can synchronize other people's local repositories through gitfetch-prune. 1. To delete the local branch, you need to confirm whether it has been merged; 2. To delete the remote branch, you need to use the --delete parameter; 3. After deletion, you should verify whether the branch is successfully removed; 4. Communicate with the team to avoid accidentally deleting shared branches; 5. Clean useless branches regularly to keep the warehouse clean.
How do I switch between Git branches?
Jul 07, 2025 am 12:03 AM
ToswitchGitbranches,firstupdatethelocalrepowithgitfetch,checkexistingbrancheswithgitbranchcommands,thenusegitcheckoutorgitswitchtochangebranches,handlinguncommittedchangesbycommitting,stashing,ordiscardingthem.WhenswitchingGitbranches,ensureyourlocal



