且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Git-显示远程分支的远程名称

更新时间:2023-11-22 12:02:10

不是最漂亮的解决方案,但我认为它通常应该可以工作.(我觉得应该有一个更好的方法,但是我暂时无法想到.)

Not the prettiest solution but I think it should generally work. (I feel like there should be a better way but I can't think of it at the moment.)

symref=$(git symbolic-ref --short HEAD)
git config --local "branch.$symref.remote"

并且,为完整起见并总结以下一些评论,可从获取远程服务器上的跟踪分支的名称(可能与本地存储库中的remote ref名称不同).branch.$ symref.merge .

And, for completeness and to sum-up some of the comments below, the name of the tracking branch on the remote (which may not be the same as the name remote ref in the local repository) is available from branch.$symref.merge.