Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

git - Git获取远程分支(Git fetch remote branch)

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 .

(我和我的同事正在使用同一个存储库,我们已经将其分为两个分支,每个分支在技术上均针对不同的项目,但是它们具有相似性,因此有时我们需要从该branch提交给* master 。)

However, I have the branch .

(但是,我有branch 。)

My question is, 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 on my end.

(回购的git clone似乎并没有为他本地创建分支,尽管我可以看到它们在结束我的努力后仍然活着。)

Also, when I originally made the branch I did -b checkout .

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

Not sure if that makes much difference?

(不知道这有什么不同吗?)

$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/discover
origin/master

$ git fetch origin discover
$ git checkout discover

These are the commands I ran.

(这些是我运行的命令。)

But it definitely is not working.

(但这绝对是行不通的。)

I want to be able to check out that branch and then push and commit back just the branches changes from various collaborators or workstations .

(我希望能够检出该分支,然后将各种协作者或工作站的分支更改推回并提交 。)

  ask by David translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 .

(以下命令将创建一个名为daves_branch的本地分支,跟踪远程分支origin / daves_branch 。)

When you push your changes the remote branch will be updated.

(当您进行更改时,远程分支将被更新。)

For most recent versions of git:

(对于最新版本的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.

(--trackgit checkout -b [branch] [remotename]/[branch]简写git checkout -b [branch] [remotename]/[branch] ,其中[remotename]是起源 ,而[branch]是相同的两倍,在这种情况下是daves_branch 。)

For git 1.5.6.5 you needed this:

(对于git 1.5.6.5,您需要这样做:)

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 1.7.2.3及更高版本,这已经足够(可能早些开始,但这是我很快能找到的最早的确认):)

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.

(请注意,在最新的git版本中,此命令将不会创建本地分支,而会将您置于“分离的HEAD”状态。)

If you want a local branch, use the --track option.

(如果要本地分支,请使用--track选项。)

Full details here: http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches

(此处有完整详细信息: http : //git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...