一般来说,这个命令的语法是:
git push <remote> [refspec]
如果省略 refspec,则简化为:
git push <remote>
它的行为取决于 git config push.default 变量中设置的内容。 git消息说:
当 push.default 设置为 'matching' 时,git 会将本地分支推送到已经存在的同名远程分支。
在 Git 2.0 中,Git 将默认采用更保守的“简单”行为,仅将当前分支推送到“git pull”用来更新当前分支的相应远程分支。
设置“匹配”模式:
git config --global push.default matching
并设置“简单”模式:
git config --global push.default simple
让我们回到您的具体案例。将提交推送到名为“origin/master”的远程会失败,因为不存在“origin/master”远程(默认远程称为“origin”)。要使其正常工作,您必须手动添加此类遥控器,例如通过调用:
git remote add origin/master <git-repository-url>
但请注意,这样的操作会让你本地的git很混乱,你将不得不处理这样的错误:
$ git push origin/master
Counting objects: 5, done.
Writing objects: 100% (3/3), 253 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:sarxos/test.git
820474f..3706ea9 master -> master
error: unable to resolve reference refs/remotes/origin/master/master: Not a directory
error: Cannot lock the ref 'refs/remotes/origin/master/master'.
还有一些其他的:
$ git fetch origin/master
error: unable to resolve reference refs/remotes/origin/master/master: Not a directory
From github.com:sarxos/test
! [new branch] master -> origin/master/master (unable to update local ref)
error: some local refs could not be updated; try running
'git remote prune origin/master' to remove any old, conflicting branches
所以我不建议使用它。
如果你想推送到 origin/master(远程名为 'origin' 和远程分支名为 'master'),你应该这样做:
git push origin master