git 将本地分支推送到 GitHub
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4752387/
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 local branch up to GitHub
提问by Noam
I have Git configured so that when I run git push
, it pushes changes to my GitHub repo. Until now I have only had a master branch.
我已经配置了 Git,这样当我运行时git push
,它会将更改推送到我的 GitHub 存储库。到目前为止,我只有一个主分支。
However, I have now created a local branch and committed to it using:
但是,我现在已经创建了一个本地分支并使用:
git checkout -b my_new_branch
git commit
What I would like to do now is push my changes on this branch to GitHub. Do I just do a git push?
我现在想做的是将我在这个分支上的更改推送到 GitHub。我只是做一个 git push 吗?
When I first set it up I did run:
当我第一次设置它时,我确实运行了:
git config push.default current
回答by Tom
I believe you're looking for git push origin my_new_branch
, assuming your origin remote is configured to hit your github repository.
我相信您正在寻找git push origin my_new_branch
,假设您的 origin 远程配置为访问您的 github 存储库。
回答by xaxxon
Depending on your local git settings, if you have a branch checked out that isn't the one you cloned or one that exists where you are trying to push, git will not push your local branch.
根据您本地的 git 设置,如果您签出的分支不是您克隆的分支或存在于您尝试推送的分支,则 git 不会推送您的本地分支。
Here is the message it provides:
这是它提供的消息:
warning: push.default is unset; its implicit value has changed in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the traditional behavior, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches to the remote branches that already exist with the same name.
Since Git 2.0, Git defaults to the more conservative 'simple' behavior, which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch.
See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git)
fatal: The current branch
MyLocalBranch
has no upstream branch. To push the current branch and set the remote as upstream, usegit push --set-upstream origin MyLocalBranch
警告:push.default 未设置;它的隐含值在 Git 2.0 中从“匹配”变为“简单”。要压制此消息并保持传统行为,请使用:
git config --global push.default 匹配
要立即取消此消息并采用新行为,请使用:
git config --global push.default 简单
当 push.default 设置为 'matching' 时,git 会将本地分支推送到已经存在的同名远程分支。
从 Git 2.0 开始,Git 默认采用更保守的“简单”行为,它只会将当前分支推送到“git pull”用来更新当前分支的相应远程分支。
请参阅“git help config”并搜索“push.default”以获取更多信息。('simple' 模式是在 Git 1.7.11 中引入的。如果您有时使用旧版本的 Git,请使用类似的模式 'current' 而不是 'simple')
致命:当前分支
MyLocalBranch
没有上游分支。要推送当前分支并将远程设置为上游,请使用git push --set-upstream origin MyLocalBranch
回答by serv-inc
If you are really lazy, you can push all local branchesby simply using
如果你真的很懒,你可以通过简单地使用来推送所有本地分支
git push --all
--all
Push all branches (i.e. refs under
refs/heads/
); cannot be used with other<refspec>
.
- 全部
推送所有分支(即 refs 下
refs/heads/
);不能与其他<refspec>
.
回答by GiaNU
If you've configured your git to push to your GitHub master repo, no matter in with branch you are, it will push to your GitHub master repo.
如果您已将 git 配置为推送到您的 GitHub 主存储库,则无论您在哪个分支,它都会推送到您的 GitHub 主存储库。
Bear in mind that, if many developers are working in the same repository, you could get a conflict.
请记住,如果许多开发人员在同一个存储库中工作,则可能会发生冲突。