Git获取远程分支 [英] Git fetch remote branch

查看:499
本文介绍了Git获取远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的同事正在研究同一个存储库,我们将它分成两个分支,每个分支在技术上针对不同的项目,但它们有相似之处,所以我们有时会想要从分支中重新提交给* master。但是,我有分支,我的同事怎么能够专门拉那个分支。回购的一个 git clone 似乎并没有为他在本地创建分支,尽管我可以在推送结束后看到它们在不受约束的情况下生活。



另外,当我最初创建分支时,我做了 -b checkout

  iMac:test_solar dave $ git branch -r 
origin / HEAD - > ;原产地/主产地
原产地/ daves_branch
产地/发掘产地
产地/主产地

git获取产地发现
git结帐发现

这是我跑过的命令。但绝对不行。我希望能够检出该分支,然后推送并恢复来自各个协作者或工作站的分支变更。

您需要创建一个跟踪远程分支的本地分支。以下命令将创建一个名为 daves_branch 的本地分支,用于跟踪远程分支 origin / daves_branch



对于大多数版本的git:

  git checkout --track origin / daves_branch 

--track 简写为 git checkout -b [branch] [remotename] / [branch] 其中[remotename]是 origin 在这种情况下和[分支]是两次相同, daves_branch 在这种情况下。

对于git 1.5.6.5,您需要:

  git checkout --track -b daves_branch origin / daves_branch 

对于git 1.7.2.3或更高版本,这已经足够了(可能已经开始更早了,但这是我能够快速找到的最早确认):

  git checkout daves_branch 

请注意,使用最近的git版本,这个命令不会创建一个本地分支,并且会将你置于'分离的HEAD'状态。如果您想要本地分支,请使用 - track 选项。
详细信息,请点击: http:/ /git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches


My colleague and I are working on the same repository we've branched it into two branches each technically for different projects, but they have similarities so we'll sometimes want to commit back to the *master from the branch.

However, I have the branch, how can my colleague pull that branch specifically. A git clone of the repo does not seem to create the branches locally for him, though I can see them live on unfuddle after a push my end.

Also, when I originally made the branch I did -b checkout. Not sure if that makes much difference?

iMac:test_solar dave$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/discover
origin/master

git fetch origin discover
git checkout discover

This is the commands I ran. But definitely not working. I want to be able to check out that branch and then push and commit back just that branches changes from various collaborators or workstations.

解决方案

You need to create a local branch that tracks a remote branch. The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. When you push your changes the remote branch will be updated.

For most versions of git:

git checkout --track origin/daves_branch

--track is shorthand for git checkout -b [branch] [remotename]/[branch] where [remotename] is origin in this case and [branch] is twice the same, daves_branch in this case.

For git 1.5.6.5 you needed this:

git checkout --track -b daves_branch origin/daves_branch

For git 1.7.2.3 and higher this is enough (might have started earlier but this is the earliest confirmation I could find quickly):

git checkout daves_branch

Note that with recent git versions, this command will not create a local branch and will put you in a 'detached HEAD' state. If you want a local branch, use the --track option. Full details here: http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches

这篇关于Git获取远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆