簡體   English   中英

gitpython:確定與(跟蹤)分支關聯的遠程

[英]gitpython: determine the remote associated to a (tracking) branch

我想確定與當前(跟蹤分支)關聯的遠程分支

我找到的解決方案有效,但感覺很奇怪,我必須解析配置才能實現我想要的。

有沒有更優雅的解決方案?

repo = git.Repo(path) 
branch = repo.active_branch
cfg =  branch.config_reader().config  
# hand crafting the section name in next line just seems clumsy
remote= cfg.get(f'branch "{branch.name}"', "remote") 

也許git.Head.tracking_branch()git.Reference.remote_name可以給你你要找的東西?

例如

repo = git.Repo(path) 
branch = repo.active_branch
remote_name = branch.tracking_branch().remote_name

暫無
暫無

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

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