$ git branch -a
* br10
master
remotes/local_c/master
remotes/origin/HEAD -> origin/master
remotes/origin/bf10
结论:br10为本地分支,bf10为远程分支
你可能遇到过一下情况:当br10与bf10未关联时,push会报错
$ git push origin
fatal: The current branch br10 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin br10
当遇到这种情况时,如何将代码快乐高效的推送到服务器呢?
-
git push orgin br10:bf10
指定分支名称,无所谓是否关联
$ git push origin br10:bf10 Everything up-to-date
-
git push --set-upstream origin bf10
同名分支关联,如果远程没有该分支,则创建
$ git push --set-upstream origin bf10 Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 6 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 260 bytes | 260.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To ../server_a/ * [new branch] bf10 -> bf10 Branch 'bf10' set up to track remote branch 'bf10' from 'origin'.
-
git push --set-upstream origin br10:bf10
通用分支关联,后续提交,只需要git push origin即可
$ git push --set-upstream origin br10:bf10 Everything up-to-date Branch 'br10' set up to track remote branch 'bf10' from 'origin'.
-
git branch --set-upstream-to=origin/bf10 br10
通用分支关联,此操作仅关联,不提交
$ git branch --set-upstream-to=origin/bf10 br10 Branch 'br10' set up to track remote branch 'bf10' from 'origin'.
-
修改config文件,位于./.git/config
- 增加内容如下:
[branch "br10"] remote = origin merge = refs/heads/bf10
- 查看配置结果:git config --local --list
$ git config --local --list core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true branch.master.remote=origin branch.master.merge=refs/heads/master branch.br10.remote=origin branch.br10.merge=refs/heads/bf10