[英]Git: for fork with multiple configured remotes, how to query for specific remote repo
我想检索为我的本地分支上游配置的远程仓库。
我可以做git remote -v
,它给了我原点和上游存储库。 但我想知道是否有办法查询特定的远程 repo ,在这种情况下是上游。
$git remote -v
origin git@github.com:origin/practice-repo.git (fetch)
origin git@github.com:origin/practice-repo.git (push)
upstream git@github.com:remoterepo/practice-repo.git (fetch)
upstream git@github.com:remoterepo/practice-repo.git (push)
一种方法是检查特殊引用@{u}
:
# works in bash, for powershell: put quotes around '@{u}'
> git rev-parse --abbrev-ref @{u}
origin/my/branch
此参考的第一部分将指示遥控器。
一种更系统的方法来提取远程跟踪分支的远程名称:
您的本地分支之一与其远程计数器部分之间的链接存储在您的 repo 的.git/config
文件中:
> cat .git/config
...
[branch "my/branch"]
remote = origin
merge = refs/heads/my/branch
...
您可以从命令行访问此信息:
# get current branch's name :
branch=$(git rev-parse --abbrev-ref HEAD)
# get config value :
git config --get branch.$branch.remote
# as a one liner :
git config --get branch.$(git rev-parse --abbrev-ref HEAD).remote
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.