git github 如何检出生产分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1897475/
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
github how to checkout production branch
提问by Roger
I have a private project hosted on github. I have a production branch of that project. I got a new machine and I need to fix something on production. This is what I did.
我有一个托管在 github 上的私人项目。我有那个项目的生产分支。我有一台新机器,我需要在生产中修理一些东西。这就是我所做的。
git clone [email protected]:userid/project.git
# now I have master branch
git co -b production
git pull origin production
Using the above mechanism I am able to get production branch but I am getting merge conflicts which I do not want to deal with right now.
使用上述机制,我能够获得生产分支,但我遇到了我现在不想处理的合并冲突。
Is there a cleaner way of jut getting the production branch code on my local machine?
有没有一种更简洁的方法可以在我的本地机器上获取生产分支代码?
回答by VonC
You could checkout directly the remote branch after fetching it
您可以在获取它后直接结帐远程分支
git fetch origin
git branch -f remote_branch_name origin/remote_branch_name
git checkout remote_branch name
or shorter:
或更短:
git checkout -b production origin/production
You would be directly working from the fetched copy of origin/production branch (no conflict there).
您将直接从原始/生产分支的获取副本中工作(那里没有冲突)。
By doing
通过做
git co -b production
git pull origin production
You are trying to merge the remote production branch into your master (in a local 'production' branch, which means potentially conflicts if your master has locallya different history than the remote origin/production branch.
您正在尝试将远程生产分支合并到您的主分支(在本地“生产”分支中,这意味着如果您的主分支在本地具有与远程源/生产分支不同的历史记录,则可能会发生冲突。
回答by Ben James
git checkout -b production
by itself will checkout a new branch called production
based on the branch you currently have checked out, the master.
git checkout -b production
本身将签出一个新分支production
,该分支基于您当前已签出的分支,即主分支。
It's likely that what you actually wanted to do was:
很可能你真正想做的是:
git checkout -b production origin/production