在 GIT 中推送一个新分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39867806/
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
Pushing a new branch in GIT
提问by John Dui
I am using GIT, and I have created a new branch (named foo
) on my local (one that doesn't exist on the repository). Now, I have made some changes to my original project (master) files and committed all those changes in this new branch. What I would now like to do is push this new branch to the remote repository. How can I do that? If I just run git push
while I am on the branch foo
, will this push the entire branch to the repo. I don't want my changes to be pushed to master. I just want to push this new branch to the main repository.
我正在使用 GIT,并且foo
在本地(存储库中不存在的分支)上创建了一个新分支(名为)。现在,我对我的原始项目(主)文件进行了一些更改,并在这个新分支中提交了所有这些更改。我现在想做的是将这个新分支推送到远程存储库。我怎样才能做到这一点?如果我只是git push
在分支上运行foo
,这是否会将整个分支推送到 repo。我不希望我的更改被推送到 master。我只想将这个新分支推送到主存储库。
采纳答案by Pranesh Ravi
Yes. It'll prompt you to set the upstream
.
是的。它会提示您设置upstream
.
Example
例子
git branch --set-upstream origin yourbranch
It's same for everything except for the branch name. Follow the on screen guidelines.
除了分支名称外,其他所有内容都相同。遵循屏幕上的指南。
回答by David
To push a branch onto a remote repository you should use this syntax
要将分支推送到远程存储库,您应该使用此语法
git push (remote) (branch)
Usually the first remote (and often the unique) is named "origin", thus in your case you would run
通常第一个遥控器(通常是唯一的)被命名为“origin”,因此在你的情况下你会运行
git push origin foo
It is usually advisable to run a slightly more complex command
通常建议运行稍微复杂的命令
git branch --set-upstream-to origin/foo
because "--set-upstream-to" (abbreviated "-u") set a tracking on that branch and will allow you to push other changes simply running
因为“--set-upstream-to”(缩写为“-u”)在该分支上设置了一个跟踪,并允许您只需运行即可推送其他更改
git push origin
"Tracking branches are local branches that have a direct relationship to a remote branch. If you're on a tracking branch and type git pull, Git automatically knows which server to fetch from and branch to merge into." (cit. git documentation)
“跟踪分支是与远程分支有直接关系的本地分支。如果您在跟踪分支上并键入 git pull,Git 会自动知道要从哪个服务器获取以及要合并到哪个服务器。” (引用。git 文档)
回答by gutte
checkout in to your local branch and use: git push -u origin <branch>
.
this will create the new branch at the remote and push all the changes
结帐到您当地的分支机构并使用:git push -u origin <branch>
。这将在远程创建新分支并推送所有更改
回答by Kris Winiarski
git push origin foo
should do the trick. Latest git versions only push single branches (so git push
would work as long as you checked out foo
) unless you change push behaviour in git config.
git push origin foo
应该做的伎俩。除非您更改 git config 中的推送行为,否则最新的 git 版本只会推送单个分支(所以git push
只要您签出就可以使用foo
)。
Reference can be found here
参考可以在这里找到
回答by yorammi
If the upstream is defined OK, run the following command:
如果上游定义为 OK,则运行以下命令:
git push origin foo:foo
回答by haiyang
use git remote -v
to show your remote repo name and url:
用于git remote -v
显示您的远程仓库名称和网址:
origin ssh://**/*.git (fetch)
origin ssh://**/*.git (push)
origin is your remote repo name at local: You can use this command to push your new branch to origin remote repo:
origin 是您在本地的远程仓库名称:您可以使用此命令将新分支推送到 origin 远程仓库:
git push origin [your-branch-name]
Like this:
像这样:
git push origin foo