A collection of common git commands

Check out the remote repository
git clone username@host:/path/to/repository


Add local modifications
git add <filename>
git add .

Submit the changes to the local
git commit -m "code commit information"


Push changes to the server
git push origin master


list all branches
git branch --all


new branch
git checkout -b local_branch

Create a new remote branch (after creating a local branch)
git push origin local_branch


Get remote branch (two ways)
git checkout -b local_branch remote_branch
or
git checkout --track remote_branch


switch branch
git checkout master


delete branch
git branch -d test_branch


merge branch
git merge <branch>


Update local repository from server
git pull


Cancel local changes
git checkout -- <filename>


discard all local changes
git fetch origin
git reset --hard origin/master


Change the remote warehouse address
git remote set-url origin <repository>


Commands commonly used in Merge
1.GUI tool:
git mergetool

2.command line:
Accept server modifications:
git checkout --theirs <filename>

Keep your own modifications:
git checkout --ours <filename>


Roll back a single file to the specified version
git checkout <commit_number> <filename>


origin is an alias for the remote repository
use command
git remote -v

You can view the remote repository pointed to by origin
origin  ssh://[email protected]/gitroot/icm_hcdh (fetch)
origin  ssh://[email protected]/gitroot/icm_hcdh (push)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326324117&siteId=291194637