簡體   English   中英

如何通過提供 repo URL 來確定 git 遠程名稱?

[英]How to determine git remote name by giving the repo URL?

我正在嘗試獲取給定 URL 的遠程名稱:

$ git ls-remote --get-url

git@github.com:foo/bar.git
$ git remote -v

origin  git@github.com:my-username/bar.git (fetch)
origin  git@github.com:my-username/bar.git (push)
upstream    git@github.com:foo/bar.git (fetch)
upstream    git@github.com:foo/bar.git (push)

有沒有辦法通過提供 URL git@github.com:foo/bar.git來確定它屬於哪個遠程來找到遠程名稱?

我不知道直接使用 git 執行此操作的方法,但您可以將結果通過管道傳輸到 grep 並對其進行格式化:

git remote -v | grep "git@github.com:foo/bar.git" | cut -f1 | head -1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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