一般来说,该命令的语法如下:
git push <remote> [refspec]
如果省略了refspec,则简化为以下内容:
git push <remote>
它的行为取决于在 git config push.default 变量中设置的内容。Git消息如下:
当 push.default 设置为 'matching' 时,git 将本地分支推送到已存在具有相同名称的远程分支。
在 Git 2.0 中,Git 将默认使用更加保守的 'simple' 行为,这只会将当前分支推送到用于更新当前分支的相应远程分支。
要设置 'matching' 模式:
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