1

Given a properly configured local, remote-tracking branch example, what is the shortest way to fetch example's remote counterpart specifically?

I could use a bare git fetch origin to fetch all branches, the counterpart included, but this would cause a large additional amount of data to be downloaded, which I'd like to avoid.

If the counterpart shares the name example, I could run git fetch origin example:, but that name similarity is not guaranteed.

I could just find out the name of the counterpart, say, counterpart, as per this question, and run git fetch origin counterpart:. But, that's two commands, which may or may not be the shortest.

So, given these restrictions, what is the shortest way to accomplish this?

LupoCani
  • 11
  • 3
  • Under which conditions would you have a tracking branch setup, pointing to some branch on the remote, but you wouldn't know the names of both of these branches? In other words, would you expect the single `git fetch` call to not be possible? – Tim Biegeleisen Apr 12 '17 at 14:38
  • @TimBiegeleisen Of course, I could just remember, or write down, the remote branch name when setting up the tracking. However, I'd like to avoid using any information from outside of git, in part because scripting is involved. Would these particulars make a useful extension to the question? – LupoCani Apr 12 '17 at 15:37
  • Maybe there isn't a one-liner then, at least nothing which you would want to wake up to and eat for breakfast. Having tracking and remote branches with different names is not that common, from what I have seen. – Tim Biegeleisen Apr 12 '17 at 15:41
  • would adding it once to `.git/config` comply with your needs? in section: `[branch "LocalBranch"]` add `fetch = +refs/heads/:refs/remotes//` so then `git fetch` would only fetch that reference. of course, there's an initial moment (which can be when setting up the remote tracking branch for the local branch) where you would have to write down the name, but it would be only one time, and not always. – odradek Apr 12 '17 at 16:29
  • @odradek That is definitely within in the scope of the question. Perhaps you should add it as an answer? – LupoCani Apr 12 '17 at 19:15
  • i'm sorry i though that that config existed but the `fetch = ` was valid for section `[remote ]` and not for `[branch ]`, my fault, please disregard my comment. however, i do think there is another way which should be very similar, i'll think about it and get back to you. – odradek Apr 12 '17 at 19:53

0 Answers0