1

Is there any sane overview for ALL branches of my local repository and all of its remotes and their relationships? (either built in or via 3rd party tools or via command line "hacks"/scripts)

Example:

Local           Loc. track.    Remote track.            Remote
--------------------------------------------------------------
mynewtest
development     ---[0↑0↓]--->  origin/development  -->  development [origin]
                               origin/testing      -->  testing [origin]
version0.5      --[45↑0↓]--->  origin/version0.5
                               origin/version0.6
version1.0      (-[1↑854↓]->)  origin/version1.0   -->  version1.0 [origin]
                                                        UITests [origin]
algoContestMia  --[12↑4↓]--->  mia/algo            -->  algo [mia]
algoContestBen  ---[4↑8↓]--->  ben/newalgo         -->  newalgo [ben]
algoContestMyA  ---[7↑0↓]--->  my/algoContest      -->  algoContest [my]
algoContestMyB  --[14↑10↓]-->  my/algoContest      -->  algoContest [my]
                               my/UITests          -->  UITests [my]

version1.0 is an example for showing matching branches, that are not set as upstream but via matching names configured for pushs (not pulls)

stuquus
  • 31
  • 3
  • The sorting was done randomly here and might be configurable, just as filtering – stuquus Jun 25 '17 at 15:48
  • `git branch -vv`? – Oliver Charlesworth Jun 25 '17 at 15:52
  • Does this give me information on a) new remote branches (origin's `UITests` in my example), b) stale remote tracking branches (`origin/version0.5` and `origin/version0.6` in my example) and c) untracked remote tracking branches (`origin/testing`, `origin/version0.6` and `my/UITests` in my example)? I don't think so – stuquus Jun 25 '17 at 15:58

1 Answers1

2

To get your local repo up to date, use git fetch. To see details on where that got you, you can use git branch -avv. To clean out stale tracking refs, use git fetch --prune.

If you want a report formatted exactly the way you've shown here look at the --format option on git for-each-ref, getting everything juuuust the way you want it is five-liner territory.

The workflow you're describing, where your only notice of branches you care about appearing and disappearing in multiple remotes is their appearance and disappearance, is remarkably chaotic. My own experience is of course limited, but I've never seen any work environment like that. Nonetheless, you can get what you need to wrangle this from git, you'll just have to collate it yourself.

git ls-remote shows all or a selection of refs from any arbitrary path or url (or remote name, which is just local-config shorthand for a path or url and a gaggle of command defaults). git for-each-ref is git ls-remote for local repos, it can also show you stuff from the local config about the refs, and can print arbitrarily-formatted (e.g. command sequences) text for each.

So for instance you can

for f in `git remote`; do git ls-remote -h $f | sed s,^,$f\\t,; done

and a pair of git for-each-refs, one for refs/heads, another for refs/remotes, to get the local sets. See the git for-each-ref docs to see what it'll tell you, I'd probably do this with just plain unix joins of the three datasets aka tables on remote name, or maybe something with sqlite if it got hairy.

stuquus
  • 31
  • 3
jthill
  • 55,082
  • 5
  • 77
  • 137
  • `git branch -avv` neither shows me new remote branches (origin's `UITests` in my example) nor does it show me if or not remote tracking branches are stale (as `origin/version0.5` and `origin/version0.6` are in my example), nor does it show me when branches are configured for push because of matching names but not set as upstream/local-tracked (as `version1.0` and `origin/version1.0` are in my example). But at least it's the closest I got to what I want by now – stuquus Jun 25 '17 at 16:28
  • `git fetch` tells you when it creates a new remote-tracking branch, that's your `UITests` example. `git fetch --prune` cleans out stale r-t-b's like your `origin/version0.[56]` examples. `git ls-remote` will tell you the current refs in any repo you've got a url (or of course remote name, which is just local shorthand for a url and command defaults) for. If you really have such a chaotic workflow that you _care_ about refname churn in multiple remotes, I'd suggest a quickie sqlite db and some join magick. – jthill Jun 25 '17 at 16:39
  • I agree that you'd usually want to have all remotes as remote-tracking branches. However I do want to keep remote-tracking branches that became stale, but I'm still working on (and eventually merging into other branches) and I want to be able to identify them in an overview so that I know I can't push to them (even when picking up work after not having worked on that repo/project for a while) – stuquus Jun 25 '17 at 16:57