我已经配置了Git,这样当我运行git push
时,它会将更改推送到我的GitHub存储库。直到现在,我只有一个主分支。
然而,我现在创建了一个本地分支并使用以下命令提交:
git checkout -b my_new_branch
git commit
我现在想把这个分支的更改推送到GitHub上。我只需要执行git push命令吗?
刚开始设置时,我运行了以下命令:
git config push.default current
我相信你正在寻找git push origin my_new_branch
,假设你的origin远程配置为连接到你的github代码仓库。
git branch --set-upstream-to=origin/my_new_branch my_new_branch
- gloriphobia根据您本地的git设置,如果您签出的分支不是您克隆的分支或者在您尝试推送的位置存在一个分支,git将不会推送您的本地分支。
以下是它提供的信息:
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 all local branches来推送所有本地分支。
git push --all
--all
推送所有分支(即
refs/heads/
下的引用);不能与其他<refspec>
一起使用。
push.default
,那么是的,git push
将会把当前分支推送到 origin,也就是你的 Github 仓库,假设你是从那里克隆的。(如果你想要指定不同的远程仓库,可以使用branch.my_new_branch.remote
。)所以你尝试过这个方法但没有成功吗? - Cascabel