在git中, 我们可以通过 git pull 命令把服务器仓库的更新拉到本地仓库中。 git pull相当于是从远程获取最新版本并merge到本地。
当git clone之后,直接git pull它会自动给远程服务器添加一个别名origin,并且创建一个本地分支master,将本地分支master绑定到上游分支origin。
且看.git/config文件就知道了:
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://gitee.com/hongjiaheng/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
所以我们可以直接git push而无需指定远端服务器的地址。
自建项目需要自行绑定,方法很简单,首先给远程服务器起个名字:
git remote add origin https://gitee.com/hongjiaheng/test.git
一般都叫origin。
接着将本地分支和服务器绑定:
git branch --set-upstream-to=origin/maste



