Reprinted from: Git Common commands
Git configuration
git config--GlobalUser.Name"Robbin"git config--GlobalUser.email"fankai#gmail.com"git config--Globalcolor.ui truegit config--Globalalias.co checkoutgit config--Globalalias.ci commitgit config--Globalalias.st statusgit config--Globalalias.br branchgit config--GlobalCore.editor"mate-w" #set Editor to use TextMateGit config-l#List all Configurations
User's git configuration file~/.gitconfig
Common git commands
View, add, submit, delete, retrieve, reset modified files
git help <command>#Show Command's Helpgit show#Show content for a commitgit show $id git co--<file>#Discard work Area modificationsgit Co. #Discard work Area modificationsgit add<file>#Submit work file modifications to local staging areagit Add. #submit all the modified work files to staging areagit rm<file>#Delete files from the repositorygit rm <file>--Cached#delete files from repository without deleting filesgit reset<file>#recovering from staging area to working filesGit Reset-- . #recovering from staging area to working filesGit Reset-- Hard#restores the state of the most recent commit, that is, discard all changes since the last commitgit ci<file>git ci. Git ci-a#combine git add, git rm and git ci to do all of these things togetherGit ci-am"some comments"git ci--Amend#modify the last commit recordgit revert< $id >#restores the state of a commit, and the recovery action itself creates a commit objectgit revert HEAD#Restore the status of the last commit
View File diff
git diff <file> # Compare current file and staging area file differences < $id 1> < $id 2> # Compare differences between two commits #git diff--staged # Compare staging Area and Repository diff git diff-- Cached # Compare staging area and Repository diff git diff-stat # just compare statistics
View Commit Record
<file> # View This file every time you submit a record git log-p <file> # view diff git for each detail modification Log-p-2 # View the last two details of the changes in the diffgit log- stat# View submission Statistics
Tig
You can use TIG instead of diff and Log on your Mac.brew install tig
Git Local Branch Management
View, toggle, create, and delete branches
Git BR-R#Viewing remote branchesgit br <new_branch>#Create a new branchGit BR-v#View the last commit information for each branchGit BR--merged#view branches that have been merged into the current branchgit br--no-merged#view branches that have not been merged into the current branchgit Co<branch>#Switch to a branchGit Co-b <new_branch>#Create a new branch and switch to the pastgit Co-b <new_branch> <branch>#Create a new new_branch based on branchgit co $id#Checkout A history commit record, but without branching information, switching to another branch will automatically deleteGit co $id-B <new_branch>#Checkout A History submission record and create a branchgit br-D <branch>#Delete a branchGit br-d <branch>#Force a branch to be removed (a branch that has not been merged will need to be forced when it is deleted)
Branch Merging and Rebase
git merge <branch> # Merge branch branches into current branch git merge origin/master--no-ff # do not fast-foward merge so that you can generate the merge submission <branch> # to rebase the master to branch, Equivalent:git co <branch> && git rebase master && git co master && git merge <branch>
git patch management (for easy development of synchronization on multiple machines)
git diff >: /Sync.patch # generate patch git apply: /Sync.patch # play patch git apply--check. /Sync.patch # Test Patch Success
Git staging management
git stash # Temporary storage git stash list # column All stash git stash apply # Recovering staged content git stash drop # Delete Staging Area
GIT Remote branch Management
git Pull#crawl all branches of remote repository update and merge to localGit pull--no-FF#Crawl All branch updates of the remote repository and merge them locally, not fast-forward mergegit fetch Origin#crawling remote repository updatesgit merge origin/Master#Merge the remote Master branch to the local current branchGit Co--track origin/Branch#track a remote branch to create the appropriate local branchgit Co-b <local_branch> origin/<remote_branch>#Create local branch based on remote branch, same as abovegit push#Push All branchesgit push Origin master#Push the local landlord branch to the remote main branchgit push-u Origin Master#Push the local landlord branch to the remote (if no remote main branch is created to initialize the remote repository)Git push Origin <local_branch>#Create remote Branch, origin is remote warehouse nameGit push Origin <local_branch>:<remote_branch>#To create a remote branchGit push Origin:<remote_branch>#Delete the local branch (git br-d <branch>) before you push to delete the remote branch
GIT Remote repository Management
Git remote-v # to view the server address and the warehouse name of git Remotes show Origin# View Remote server warehouse status git remote add origin [email protected] github:robbin/robbin_site.git # Add remote Warehouse address git remote set-url origin [email protected] github.com:robbin/# set the remote warehouse address ( Used to modify the remote warehouse address)git remote rm <repository> # Delete a repository
Create a remote Warehouse
git clone--Bare robbin_site robbin_site.git#Create a version-only warehouse with a versioned projectScp-r my_project.git [email protected] git.csdn.net:~#upload the repository to the servermkdir robbin_site.git&& CD robbin_site.git && git--Bare init#Create a pure warehouse on the servergit remote add origin [email protected] github.com:robbin/Robbin_site.git#set the remote warehouse addressgit push-u Origin Master#Client First Commitgit push-u origin Develop#The local develop branch is submitted to the remote develop branch for the first time, and the trackgit remote set-Head Origin Master#set head of remote warehouse to point to master branch
You can also command settings to track remote libraries and local libraries
Git branch--set-upstream master origin/--set-upstream Develop Origin/develop
Reproduced Common git commands