Home  >  Q&A  >  body text

github - git 如何在push的时候绑定远程branch?

  1. 初始化本地 git 库 git init

  2. 在github上创建库

  3. 添加远程push地址

    git remote add origin(备注:为什么这个origin不能修改?) git@git.com/xxx/xxx.git

  4. 我认为的是 origin 就相当于远程库了,所以 绑定远程分支

    git branch --set-upstream-to master origin/master

我操作的有问题吗?报错为:

git branch --set-upstream-to master origin/master
fatal: branch 'origin/master' does not exist

最后我是这么解决的 :

git push -u origin master

谢谢.

PHP中文网PHP中文网2727 days ago695

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:50:59

    The origin/master branch did not exist before your first push

    If you change the background, it may be fine. For example, after git clone, change the upstream of the new local branch to origin/master

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-02 09:50:59

    Add git fetch after step 3.

    git init 初始化本地仓库,默认分支是 master.

    git remote add origin(Note: Why can’t this origin be modified?) git@git.com/xxx/xxx.git

    The name of

    origin can be modified at will, and N remote repositories can be added. But at this time the warehouse is remote and not available locally.

    After executing git fetch, the remote warehouse will be obtained locally, and the branch is origin/*, that is, all branches of the remote warehouse will be pulled down. The remote
    master branch corresponds to the local origin/master.

    After executing git branch --set-upstream-to master origin/master, set the remote master branch as the local tracking branch. When executing git pull, you can Directly pull the remote master to the local origin/master branch and master branch. If you execute git branch --set-upstream-to master origin/master 后,将远程的 master 分支设置为本地的跟踪分支,当执行 git pull 时,可以直接将远程的 master 直接拉取到本地的 origin/master 分支和 master 分支,如果执行 git fetch, only the remote master branch will be pulled to the local origin/master branch.

    reply
    0
  • Cancelreply