git - 找出本地分支正在跟踪哪个远程

标签 git

这不是 Find out which remote branch a local branch is tracking , 如果我有多个 Remote ,我可能在所有 Remote 中都有“主人”。 git branch返回 master 但我不知道我所在的 master 分支是在 remoteFoo 还是 remoteBar 中。例如,我可能会这样做:

git clone someRepo.git
cd someRepo
git remote add anotherRemote otherremoteURL

然后git remote显示
someRepo
anotherRemote

我可以做 git checkout -b master someRepo/mastergit checkout -b master anotherRemote/mastergit branch在这两种情况下都会说“主人”。我如何取回第一部分,“someRepo”或“anotherRemote”?

你会认为我可以使用 git remote show但它需要一个参数,即您想要获取信息的 Remote 的名称。
$ git remote show origin
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git remote show
someRepo
anotherRemote

git branch我得到了当前情况的指示:
$ git branch
  hold
* master
  old-stuff
  refactor

但是 git remote 中没有“*”输出。

最佳答案

您可能想尝试以下这些以查看详细信息。

git remote -v
git remote -v show origin

下面的示例输出:
dmasi@:/var/www/pirate_booty$ git remote -v
origin  git@bitbucket.org:dmasi/pirate_booty_calculator.git (fetch)
origin  git@bitbucket.org:dmasi/pirate_booty_calculator.git (push)

dmasi@:/var/www/pirate_booty$ git remote -v show origin
* remote origin
  Fetch URL: git@bitbucket.org:dmasi/pirate_booty_calculator.git
  Push  URL: git@bitbucket.org:dmasi/pirate_booty_calculator.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

关于git - 找出本地分支正在跟踪哪个远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12609415/

相关文章:

git - 如果从未提交过,您可以撤消 'git reset --hard HEAD' 吗?

git - 如何恢复 merge 到我 fork 的仓库的 pull 请求,而不是 merge 到我的该仓库副本

Git stash 删除添加的更改

linux - Docker:从 Win10 安装到运行 ubuntu 的容器的目录中不允许进行 git 操作

没有 SSH 的 Git pull ?

git - "git add"和 "git update-index"有什么区别

git - 无法访问远程机器 git 存储库

git - 如何将当前日期设置为 git 提交消息

git - 尝试在 Windows 中修改 Git 配置文件时出错

git commit 删除 repo 中的所有文件