簡體   English   中英

Git:對於具有多個配置遠程的fork,如何查詢特定的遠程repo

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM