git Gitlab 拉一个分支到本地机器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35365793/
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
Gitlab Pull a branch to the local machine
提问by lars111
I want to copy a branch of the online repository (Gitlab) to my local machine. Let's assume the branch is called "Version1" - then I want to copy this branch to a new branch called "Version2" on my local machine. Because I dont want to overwrite this branch later. The problem i got is the following: Every time I create a new branch on my local machine it is a copy of the branch that I was before.
我想将在线存储库 (Gitlab) 的一个分支复制到我的本地机器上。假设分支名为“Version1” - 然后我想将此分支复制到本地机器上名为“Version2”的新分支。因为我不想以后覆盖这个分支。我遇到的问题如下:每次我在本地机器上创建一个新分支时,它都是我之前所在分支的副本。
git pull origin Version1
does not work as i want.
不像我想要的那样工作。
Would be great if someone could help.
如果有人可以提供帮助,那就太好了。
回答by Jonathan.Brink
You can create a local branch on your machine that is based off of the Version
branch.
您可以在您的机器上创建一个基于分支的本地Version
分支。
Use the checkout
command with -b
.
将checkout
命令与-b
.
First switch to the branch you want to "copy":
首先切换到要“复制”的分支:
git checkout Version1
Next, create your own branch that is based off of Version1
:
接下来,创建您自己的基于以下的分支Version1
:
git checkout -b Version2
Now, when you create commits while on the Version2
branch, your local copy of Version1
will remain unchanged.
现在,当您在Version2
分支上创建提交时,您的本地副本Version1
将保持不变。
Hereis a good article to learn more about branching.
这是一篇很好的文章,可以了解有关分支的更多信息。