git 如何在不合并的情况下下载新的远程分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23848845/
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 18:07:03  来源:igfitidea点击:

How can I download a new remote branch without merging?

git

提问by ygoe

I've been working on the master branch in my Git repository for a while. It's hosted on GitHub and cloned on two of my computers. Now I started a new branch on one computer and pushed it to GitHub. Now they know both branches, but the other computer still only knows about the master branch, not the feature branch.

我一直在我的 Git 存储库中的 master 分支上工作一段时间。它托管在 GitHub 上并克隆到我的两台计算机上。现在我在一台计算机上创建了一个新分支并将其推送到 GitHub。现在他们知道两个分支,但另一台计算机仍然只知道 master 分支,而不知道 feature 分支。

When I try to pull the feature branch from GitHub, Git will merge it into my master, which is not what I want.

当我尝试从 GitHub 拉取功能分支时,Git 会将其合并到我的 master 中,这不是我想要的。

How can I download the feature branch from GitHub into my local repository and end up having the two branches and no merge? I'm going to merge them when it's ready, not now.

如何将功能分支从 GitHub 下载到我的本地存储库并最终拥有两个分支而没有合并?准备好后,我将合并它们,而不是现在。

If possible, I'm interested in what to do with TortoiseGit.

如果可能,我对如何使用 TortoiseGit 感兴趣。

回答by brock

You can do git fetch originon the command line. This will update your local copy so that it knows about the new branch. Then, if you want to checkout the new branch, simply git checkout BRANCHNAMEshould track the remote.

你可以git fetch origin在命令行上做。这将更新您的本地副本,以便它了解新分支。然后,如果您想签出新分支,只需git checkout BRANCHNAME跟踪遥控器即可。

回答by VonC

A git fetchwouldn't merge anything:

Agit fetch不会合并任何东西:

git fetch
git checkout -b yourSecondBranch origin/yourSecondBranch 
# or simpler, since git 1.6+:
git checkout yourSecondBranch

(Here I fetch by default the remote 'origin', which should reference the GitHub repo)

(这里我默认获取远程'origin',它应该引用GitHub repo)

See more at "git checkout remote branch"

在“ git checkout remote branch”中查看更多信息