码迷,mamicode.com
首页 > 其他好文 > 详细

git - 远程分支

时间:2015-07-25 16:36:10      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:

对于用户来说,git给人提交到本地的机会。我们可以在自己的机器上创建不同的branch,来测试和存放不同的代码。

对于代码管理员而言,git有许多优良的特性。管理着不同的分支,同一套源代码可以出不一样的版本。

 

市面上有非常多的相关书籍和教程。我个人比较喜欢的是:

ProGit(中文版)    http://git.oschina.net/progit/  

关于git的master和origin    http://lishicongli.blog.163.com/blog/static/1468259020132125247302/ 

刚开始的时候我没注意master和origin这两个名称,直到操作远程分支的时候,我才有了比较多的了解

 

远程分支的操作

# 查看远程分支,会显示出远程分支名与url
$ git remote -v
origin    ssh://RustFisher@192.168.1.1:29418/workspace/product1 (fetch)
origin    ssh://RustFisher@192.168.1.1:29418/workspace/product1 (push)

这里采用gerrit来进行代码审核,用默认的29418端口

如何添加远程分支?

使用git remote add指令,例如:

$ git remote add r1 ssh://RustFisher@192.168.1.1:29418/work
# 添加一个远程分支,url为ssh://RustFisher@192.168.1.1:29418/work;分支别名为r1
# 查看已有的远程分支
$ git remote -v
r1    ssh://RustFisher@192.168.1.1:29418/work (fetch)
r1    ssh://RustFisher@192.168.1.1:29418/work (push)
# 这时使用git pull同步代码,git会问你要分支名
$ git pull
fatal: 未指定远程版本库。请通过一个URL或远程版本库名指定,用以获取新提交。
# 我们可以选择从r1库同步代码
$ git pull r1
# 如果不想每次git pull都写上分支名,那么可以把远程分支命名为origin,git会默认从这里pull
$ git remote rm r1
# 看看还有没有远程分支r1
$ git remote -v
# 开始添加
$ git remote add origin ssh://RustFisher@192.168.1.1:29418/work
$ git remote -v
origin    ssh://RustFisher@192.168.1.1:29418/work (fetch)
origin    ssh://RustFisher@192.168.1.1:29418/work (push)
# 添加成功,pull一次试试
$ git pull
另一个工程里,查看所有分支,包括远程分支
$ git branch -a
* working
  remotes/origin/demo1
  remotes/origin/HEAD -> origin/master
  remotes/origin/demo2
  remotes/origin/demo3
  remotes/origin/working
  remotes/origin/master
  remotes/origin/tab1 

git - 远程分支

标签:

原文地址:http://www.cnblogs.com/rustfisher/p/4676053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!