-2

I have a folder with subfolders that are git repos. I would like to have a quick way to get an overview of what branch I am currently on in each of these repos.

Example:

Folder
 - subfolder1 : Master
 - subfolder2 : Master
 - subfolder4 : Development
 - etc ...

Note: I am using Ubuntu 16.04

LeGEC
  • 29,595
  • 2
  • 37
  • 78
  • 1
    Check this thread sir http://stackoverflow.com/questions/6245570/how-to-get-the-current-branch-name-in-git – jeanawhou Mar 24 '17 at 12:06
  • Maybe there is an easier way, but I figured out using this bash command: `for i in ~/folder/*; do (cd $i; echo $i; git branch) done` – Mohammad El-Wali Mar 24 '17 at 12:10
  • @jeanawhou thank you for your reply, his problem is slightly different than mine. I don't need to know what branch I'm in one folder at a time. I am looking for a way of listing the branches I'm on in several folder at the same time. For now bash command hos solved it for me, but I would like to hear if any one else has some suggestions of how to do it. – Mohammad El-Wali Mar 24 '17 at 12:17

1 Answers1

1

The following will "somehow" name the checked out commit. "somehow" meaning if no branch is checked out, it tries to name by tag and so on.

ls -1 | xargs -i sh -c 'echo -n "{}: "; git -C "{}" name-rev --name-only --no-undefined --always HEAD'

The following will only show checked out branches and otherwise detached HEAD

ls -1 | xargs -i sh -c 'echo -n "{}: "; (git -C "{}" symbolic-ref HEAD 2>/dev/null || echo "           detached HEAD") | cut -c 12-'
Vampire
  • 31,050
  • 2
  • 58
  • 88