git 将本地主提交推送到远程分支

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

Push local master commits to remote branch

git

提问by Evan Kroske

I've been working on a local clone of a remote git repository, committing my changes to my local master branch. Now, I want to push my commits to the remote repository. However, I want to keep my local commits separate from the remote master branch, so that I don't break anything. How can I push my local commits to a new remote branch?

我一直在研究远程 git 存储库的本地克隆,将我的更改提交到我的本地 master 分支。现在,我想将我的提交推送到远程存储库。但是,我想让我的本地提交与远程主分支分开,这样我就不会破坏任何东西。如何将本地提交推送到新的远程分支?

回答by Daenyth

You should run git help push, which will tell you about the syntax for the refspec that you push to. In short, git push <remotename> <local_branch_name>:<remote_branch_name>

您应该运行git help push,它会告诉您推送到的 refspec 的语法。简而言之,git push <remotename> <local_branch_name>:<remote_branch_name>

回答by John Henckel

I was not able to do this with a single command. First I commit all my changes to my local master. Then I create a new local branch called "mybranch" using

我无法使用单个命令执行此操作。首先,我将所有更改提交给本地 master。然后我使用创建一个名为“mybranch”的新本地分支

git checkout -b mybranch

and then I pushed that using

然后我推了使用

git push -u origin mybranch

in my case originis the remote name. Your remote name might be different. You can use git remote -vto see what your remote name should be.

在我的情况下origin是远程名称。您的远程名称可能不同。您可以使用git remote -v来查看您的远程名称应该是什么。

After the push, if you want, you can get rid of your local branch using these two commands

推送后,如果你愿意,你可以使用这两个命令摆脱你的本地分支

git checkout master
git branch -d mybranch

hope that helps.

希望有帮助。

回答by Fady Ayoub

What I did was creating a new local branch for example name it test1

我所做的是创建一个新的本地分支,例如将其命名为 test1

git checkout -b test1

git checkout -b test1

this command will create a branch and switch to it directly, and then push your new local branch to your remote repository either GitHub or GitLab by typing

此命令将创建一个分支并直接切换到它,然后通过键入将新的本地分支推送到 GitHub 或 GitLab 的远程存储库

git push origin test1

git push origin test1

don't forget to check the correct link by typing.

不要忘记通过键入来检查正确的链接。

git remote --v

git远程--v