git 如何将更改推送到远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4697326/
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
How can I push my changes to a remote branch
提问by michael
I am on a master branch 'master' and I have 1 commit ahead I want to create a new remote branch called 'new_remote' and push my commit there?
我在一个主分支“master”上,我有 1 个提交,我想创建一个名为“new_remote”的新远程分支并将我的提交推送到那里?
$ git branch
* master
$ git remote
old_remote
$ git status
# On branch master
# Your branch is ahead of 'old_remote/master' by 1 commit.
I want to push my commit to a new branch on remote called 'new remote' Thank you.
我想将我的提交推送到名为“new remote”的远程新分支,谢谢。
回答by karlphillip
If you are currently working on local branch master, and the new remote branch has not been created yet:
如果您当前正在处理本地分支master,并且尚未创建新的远程分支:
git checkout -b new_branch // creates a local branch (as a copy of the current)
git push origin new_branch // push it to the remote server
回答by Antoine Pelisse
If you want to push your master
branch into a newbranch
on the remote repository called origin
then you can run:
如果要将master
分支推送到newbranch
名为的远程存储库上,origin
则可以运行:
git push origin master:newbranch
回答by Ajay Reddy
Although what you are trying is perfectly legal in git, from a general best practice standpoint (when you have many parallel lines of development) I'd suggest to create a local tracking branch and push it to your remote.
尽管您尝试的操作在 git 中完全合法,但从一般最佳实践的角度来看(当您有许多并行开发线时),我建议创建一个本地跟踪分支并将其推送到您的远程。
git branch --track local_branch remote_branch
回答by Chetan Laddha
git push origin localBranchName:master
More generally,
更普遍,
git push remote local_branch_Name:remote_branch_name
回答by farnoy
I think you just want to push your changes, so:
我认为你只是想推动你的改变,所以:
git push old_remote master
should be enough for you. The first parameter for git push
is the remote you want to update (in your case that's old_remote') and the second is the branch you want to push.
对你来说应该足够了。第一个参数git push
是你想要更新的远程(在你的例子中是 old_remote'),第二个是你想要推送的分支。
Instead of specifying branch with name, you can use --all
like this:
您可以--all
像这样使用,而不是使用名称指定分支:
git push old_remote --all