Search code examples
gitrepositorybranchls

Displaying current branch while outside of git repository directory?


In the Git Bash, repositories list what branch they are on when you are inside the repo directory.

Currently I'm working on a project that compiles a group of repositories into one product and when I'm in the directory that contains all of those repositories, it would be very helpful to be able to see the current branch for each one listed next to it when I ls.

Is there a setting or a way I could make Git Bash behave this way? Perhaps an ls flag I'm unfamiliar with (tho this seems doubtful)?


Solution

  • The command you can execute from your current folder is:

    git --git-dir=subfolder/.git branch --show-current
    

    (--show-current is available with Git 2.22, Q2 2019)

    So you need to loop over your subfolder and use that to get a list of all branches:

    As a variant, with -execdir:

    find . -maxdepth 2 -type d -name ".git" -exec echo -n "{} :" ; -execdir git branch --show-current ;
    

    Depending on your bash, you might need to escape the ;: \;