git 如何从一个分支推送到另一个分支并结帐?

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

How to push from one branch to another and checkout?

git

提问by startupsmith

I am trying to implement the setup outlined here http://toroid.org/ams/git-website-howtobut with one difference. On my local repository I want to use a branch different to master.

我正在尝试实施此处概述的设置http://toroid.org/ams/git-website-howto但有一个区别。在我的本地存储库中,我想使用与 master 不同的分支。

So when I go to push the initial files rather than push the master files I want to push the files from my demo branch to the master branch on the remote repository. For example:

所以当我去推送初始文件而不是推送主文件时,我想将文件从我的演示分支推送到远程存储库上的主分支。例如:

git push web +master:refs/heads/demo

But when I do this I get the following error after it completes uploading all of the files:

但是,当我这样做时,在完成上传所有文件后出现以下错误:

remote: fatal: You are on a branch yet to be born

Is it possible to do what I am trying to do with this setup?

是否可以使用此设置执行我想要执行的操作?

回答by David M. Syzdek

If the local branch is called "demo" and you want to push to branch called "master" on the remote called "web", then do the following:

如果本地分支名为“demo”,并且您想推送到名为“web”的远程分支上名为“master”的分支,请执行以下操作:

git push web demo:master

If you want to merge from the "master" branch on the remote "web" into your current branch, you can do the following:

如果要从远程“web”上的“master”分支合并到当前分支,可以执行以下操作:

git fetch web
git merge web/master