如何执行 git pull 到特定分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5509677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:30:02  来源:igfitidea点击:

How do I do a git pull to a specific branch?

git

提问by marcamillion

I am trying to pull from my heroku remote, I get this message:

我正在尝试从我的 heroku 遥控器中拉出,我收到以下消息:

>git pull heroku
You asked to pull from the remote 'heroku', but did not specify
a branch. Because this is not the default configured remote

My local branch is 'develop'.

我的本地分支是“开发”。

How do I pull from Heroku to my local branch 'develop' ?

我如何从 Heroku 拉到我的本地分支“开发”?

Thanks.

谢谢。

采纳答案by Chetan

Updated answer: You need to specify what branch you want to pull from, since your local branch is not configured to pull from heroku's master.

更新的答案:您需要指定要从哪个分支拉取,因为您的本地分支未配置为从heroku's拉取master

So try something like:

所以尝试这样的事情:

git pull heroku master

Remember that you have to have checked out developin order for this command to pull to the local branch develop.

请记住,您必须已签出develop才能将此命令拉到本地分支develop

回答by Cameron Skinner

When you pull you have to specify which remote branch you want to pull from. It doesn't make any sense to pull from just "heroku" because it may have multiple branches and Git doesn't know which one you want.

拉取时,您必须指定要从哪个远程分支拉取。仅从“heroku”中提取没有任何意义,因为它可能有多个分支,而 Git 不知道您想要哪个分支。

If there is only one branch on your remote then it's probably called "master". Try:

如果您的遥控器上只有一个分支,那么它可能被称为“master”。尝试:

git checkout develop
git pull heroku master

This puts you into your local "develop" branch then pulls the "master" branch from the repository called "heroku".

这会将您置于本地的“develop”分支,然后从名为“heroku”的存储库中提取“master”分支。

回答by VonC

Note: if you want to push/pull by default to heroku/masterfrom your developbranch, you can configure it with:

注意:如果你想默认heroku/master从你的develop分支推/拉,你可以配置它:

git branch --set-upstream-to develop heroku/master

You can check your merge policy on the developbranch with a:

您可以使用以下命令检查develop分支上的合并策略:

git config branch.develop.merge

Note: As commentedby Animay, since Git 1.8, --set-upstreamis renamed --set-upstream-to.
--trackis also possible, although slightly different.

注意:正如Animay评论的,自 Git 1.8 起,已重命名为. 也是可能的,虽然略有不同--set-upstream--set-upstream-to
--track

回答by Rocky Inde

As of this writing, the command git pullprovides the answer. When I try to git pullwithout any further arguments, it provided me the following information:

在撰写本文时,该命令git pull提供了答案。当我尝试git pull没有任何进一步的论据时,它为我提供了以下信息:

rockyinde.desktop% git pull
remote: Counting objects: 143, done.
remote: Compressing objects: 100% (95/95), done.
remote: Total 143 (delta 75), reused 87 (delta 23)
Receiving objects: 100% (143/143), 29.59 KiB | 0 bytes/s, done.
Resolving deltas: 100% (75/75), completed with 33 local objects.
From ssh://git.rockyinde.com:<port>/code/myproject
   2d232ds..1hw1f84  frontline   -> rockyremote/frontline

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

   git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

   git branch --set-upstream-to=<remote>/<branch> develop

So, all you need to be looking at (in the above output) is:

因此,您需要查看的所有内容(在上面的输出中)是:

From ssh://git.rockyinde.com:<port>/code/myproject
   2d232ds..1hw1f84  frontline   -> rockyremote/frontline

which specifies your remote/branchinformation. And so, in my case it is:

指定您的remote/branch信息。因此,就我而言,它是:

git pull rockyremote frontline