0

I have remote with special fetchspec

[remote "devall"]
url = https://BNahum90789@dcilpa670/scm/devops/dev4all.git
fetch = +refs/heads/dev/BNahum90789_2/*:refs/remotes/dev_BNahum90789/*

Now I push to remote:

git push -u devall my:dev/BNahum90789_2/my_on_remote

So my remote tracking branch looks like this:

git rev-parse --symbolic-full-name dev_BNahum90789/my_on_remote
refs/remotes/dev_BNahum90789/my_on_remote

Given this remote tracking branch 'refs/remotes/dev_BNahum90789/my_on_remote' how can I find name of remote and branch on remote ?? (Please note, it doesn't contains remote name nor local tracking branch !!!)

(The only way I can think on, is to go over all fetch-specs of all remotes and find which one does match)

Thanks Boaz

Boaz Nahum
  • 1,049
  • 8
  • 9
  • 2
    Possible duplicate of [how do I get git to show me which branches are tracking what?](https://stackoverflow.com/questions/4950725/how-do-i-get-git-to-show-me-which-branches-are-tracking-what) – JamesD May 15 '18 at 21:37
  • This isn't a dup of that, this is about finding which branches track a particular local remote-tracking branch, but branch -vvv shows you the actual remote branch that's being tracked, not the local tracking proxy. – jthill May 16 '18 at 16:05

2 Answers2

1

You are correct, for very difficult cases like this one, you must iterate through all fetch-specs for all remotes. This is similar to what Git does internally when fetching: it takes each reference presented by the other Git (as shown by git ls-remote remote-url) and runs it through all the fetch lines for that particular remote, to see what name(s) it maps to. If more than one input name maps to that output name, that's an error.1

In your case, you don't have the input name, but rather the output name. There's no guarantee that there is a unique mapping from output name to possible input name. You can of course run git ls-remote on that remote to see what input names they have, and hence repeat the work that Git would do.

(It's far simpler to go from the local branch names, which either have that remote-tracking name set as their upstream, or don't.)


1In some versions of Git, you don't get any actual error, you just get weird behavior.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Branches track the actual upstream branch ref name, not the remote-tracking name. That surprised me too. – jthill May 16 '18 at 03:25
  • @torek Thanks. Any reason to to fetch to all that match? – Boaz Nahum May 16 '18 at 07:52
  • @jthill: It's a holdover from before there were named remotes, I believe. BoazNahum: I'm not sure what you mean. – torek May 16 '18 at 14:54
  • I have it as useful: switching remotes doesn't invalidate the tracking branch, local-tracking just uses `.` as the remote. – jthill May 16 '18 at 16:03
0
[remote "devall"]
url = https://BNahum90789@dcilpa670/scm/devops/dev4all.git
fetch = +refs/heads/dev/BNahum90789_2/*:refs/remotes/dev_BNahum90789/*

Git embeds the remote name in remote-tracking branch names by default. When you took that out, you didn't break anything, everything tracking the r-t-b's still tracks them without that, fetch still updates them, it all still works. It just makes it a little harder to follow.

how can I find name of remote and branch on remote

Hunt up the refspecs that map your to your r-t-b name.

git config --get-regexp fetch refs/remotes/dev_BNahum90789

to see all the refspecs that map to that r-t-b name. In your case, you'll get at least

remote.devall.fetch +refs/heads/dev/BNahum90789_2/*:refs/remotes/dev_BNahum90789/*

and for a one-off it's easy to eyeball the mapping. If you made multiple remotes map to the same tracking prefix that would likely cause trouble and I think this wouldn't be be your first indication of it so I'll ignore the possibility.

By the way, I have

git config alias.grl '!f() { git config --local --get-regexp "${@-.}"; }; f' 
git config alias.gr '!f() { git config --get-regexp "${@-.}"; }; f'

which defaults the search to show-everything and makes the search much easier to type, git grl fetch BNahum would probably do it.

jthill
  • 55,082
  • 5
  • 77
  • 137