我印象中 只要本地分支和远程分支建立了跟踪关系就可以直接使用git push了不用再指定远程分支名了 我今天遇到了问题 说我本地分支名和远程分支名不同名 让我必须指定写出远程分支名,我不理解难道不是建立跟踪关系就可以了吗 不同名不行吗?git push省略远程分支名时 具体原理是什么
本地分支叫 xdd
git branch -vv 输出的就是sandbox/devops/web_dev
fatal: The upstream branch of your current branch does not matchthe name of your current branch. To push to the upstream branchon the remote, use git push origin HEAD:sandbox/devops/web_devTo push to the branch of the same name on the remote, use git push origin HEADTo choose either option permanently, see push.default in 'git help config'.
git-push
When the command line does not specify what to push with <refspec>... arguments or --all, --mirror, --tags options, the command finds the default <refspec> by consulting remote.*.push configuration, and if it is not found, honors push.default configuration to decide what to push (See git-config[1] for the meaning of push.default).
When neither the command-line nor the configuration specify what to push, the default behavior is used, which corresponds to the simple value for push.default: the current branch is pushed to the corresponding upstream branch, but as a safety measure, the push is aborted if the upstream branch does not have the same name as the local one.
啥都不写会看配置(其中一个是 push.default)。如果配置也没有,就用默认。但是因为默认在不同版本之间曾经变过,所以使用默认值时一些可能比较危险的情况会被拒绝,比如本地和远端 branch 名字不一样的时候。
push.default 在 2.0 以后的默认值是 simple ,这只会 push 同名 branch 。要 push 到 upstream (即使不同名)去,push.default 需要设置为 upstream 。
根据需要设置一下 push.default 就好了。