Git 正在推送到错误的远程分支

Git is pushing to wrong remote branch

我做了什么:

$ git clone git@github.com:myuser/doctrine-extensions.git
$ cd doctrine-extensions
$ git checkout -b rollback_positions origin/master

然后我做了一些更改,提交和状态说:

 $ git status
 On branch rollback_positions
 Your branch is ahead of 'origin/master' by 1 commit.
    (use "git push" to publish your local commits)

现在我想推送到远程origin到一个新的分支rollback_positions。但是 Git 不会创建新的远程分支,而是使用 master:

$ git push origin rollback_positions
Counting objects: 88, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (17/17), 4.50 KiB | 0 bytes/s, done.
Total 17 (delta 10), reused 0 (delta 0)
To git@github.com:myuser/doctrine-extensions.git
   b1c3643..6a09dc9  rollback_positions -> master

怎么了?应该是 rollback_positions -> rollback_positions.

git checkout -b rollback_positions origin/master  

rollback_positions 的上游分支设置为 origin/master。您可以在推送时明确指定远程名称:

git push -u origin rollback_positions:rollback_positions

选项-u 将设置上游。您也可以使用 --set-upstream--unset-upstream 来更改 upstream。 为避免下次使用:

git checkout --no-track -b rollback_positions origin/master

Jubobs所说。