Preface: work collaboratively using git development work, most of the time using several commonly used commands to get the job done. But for the meaning behind it is like gulping, not quite understand its flavor. So access to information, the use of the usual commands to do further research to understand. Know these, but know why.
1. The basic command flow
Most of the work, we use the following command to complete the operation to submit code to the remote repository. Commands listed below for your review of commonly used commands, not used git commit code can first understand the following basic commands to learn on their own.
$ git status #查看当前工作区状态
$ git add {filename}
$ git commit -m "comment"
$ git push -u origin HEAD: master
2. Detailed Instructions
2.1 git pull
git pull <远程主机名> <远程分支名>:<本地分支名>
For example, to retrieve origin
the host next
branch, with local master
branches merge, need be written as follows.
git pull origin next:master
If the remote branches are combined with the current branch, the portion of the colon may be omitted.
git pull origin next
The above represents a command to retrieve origin/next
the branch, and then merged with the current branch. In essence, this is equivalent to do first git fetch
, do git merge
.
git fetch origin
git merge origin/next
2.2 git push
git push
Command is used to update the local branch, pushed to the remote host. Its format git pull
command similar.
git push <远程主机名> <本地分支名>:<远程分支名>
If you omit the remote branch name, it said it would push the local branch with the presence of "trace relationship" remote branch (usually both of the same name), if the remote branch does not exist, it will be new.
git push origin master
Represents the above command, the local master
branch pushed origin
host master
branch. If the latter does not exist, it is new. If you omit the local branch name, then delete the specified remote branch, because this is equivalent to pushing an empty local branches to remote branches.
git push origin :master
# 等同于
git push origin --delete master
If the current relationship between the presence of trace branches and multiple hosts, you can use the -u
option to specify a default host so that you can later use without any parametersgit push
git push -u origin master
Part Reference: http://www.ruanyifeng.com/blog/2014/06/git_remote.html