方式一
1. 查看远程仓库
$ git remote -v
eoecn https://github.com/eoecn/android-app.git (fetch)
eoecn https://github.com/eoecn/android-app.git (push)
origin https://github.com/com360/android-app.git (fetch)
origin https://github.com/com360/android-app.git (push)
从上面的结果可以看出,远程仓库有两个,一个是eoecn,一个是origin
2 ,从远程获取最新版本到本地
$ git fetch origin masterFrom https://github.com/com360/android-app
* branch master -> FETCH_HEAD
$ git fetch origin master 这句的意思是:从远程的origin仓库的master分支下载代码到本地的origin master
3. 比较本地的仓库和远程参考的区别
$ git log -p master.. origin/master
4. 把远程下载下来的代码合并到本地仓库,远程的和本地的合并
$ git merge origin/master
方式二
1.查看远程分支,和上面的第一步相同
2. 从远程获取最新版本到本地
$ git fetch origin master:tempFrom https://github.com/com360/android-app
* [new branch] master -> temp
git fetch origin master:temp 这句命令的意思是:从远程的origin仓库的master分支下载到本地并新建一个分支temp
- 比较本地的仓库和远程参考的区别
$ git diff temp
命令的意思是:比较master分支和temp分支的不同
4. 合并temp分支到master分支
$ git merge temp
5.如果不想要temp分支了,可以删除此分支
$ git branch -d temp
如果该分支没有合并到主分支会报错,可以用以下命令强制删除git branch -D <分支名>
总结:方式二更好理解,更安全,对于pull也可以更新代码到本地,相当于fetch+merge,多人写作的话不够安全。