2

I've got multiple git repos under a directory, and I was wondering whether there was some functionality in git to iterate each directory, check whether there are any uncommitted changes and report those to me?

I could run this every morning to ensure everything is up to date.

It's just that on any one day, I'll be working with multiple repos and I'll forget to commit my changes, which can cause conflicts when I realise much later on to commit them.

Chris

Chris
  • 4,594
  • 4
  • 29
  • 39
  • 1
    I've never used submodules, so I'm not confident enough to post an answer saying they will work. But, if there is a way in git to do it, submodules would be it. If not, pick the scripting language of your choice and hack it out:) – Andy Sep 30 '11 at 01:20
  • I don't think the question was referring to submodules. It looks like he just has a bunch of projects in, say, his home directory. – erjiang Sep 30 '11 at 01:22
  • From what I have understood, a submodule would combine them all, while leaving the individual repo intact, he could than get their status in a single git command At least that is how I've understood them, but like I said, I've never used them. – Andy Sep 30 '11 at 01:29

6 Answers6

1

I wrote a command-line tool gita for this purpose. It can display the status of all repos, including the edit status, the relation to remote branch, etc. It also batch executes commands from any working directory.

You can also group the repos. For your project structure, you can run

gita add -r <root>

which will automatically add the subordinate repos into a group.

Then gita ll root will display the relevant information. gita <command> root will batch run the command on repos in the root group. You can surely run command on specified repos from any working directory too.

There are other functionalities such as setting context, defining custom commands, etc. Installation is pip3 install -U gita. You can find more information on github.

enter image description here

The gita ll command shows 3 possible symbols next to the branch name, which indicates

  • +: staged changes
  • *: unstaged changes
  • _: untracked files/folders

The branch names are colored in 5 ways

color meaning
white local has no remote
green local is the same as remote
red local has diverged from remote
purple local is ahead of remote (good for push)
yellow local is behind remote (good for merge)
nos
  • 19,875
  • 27
  • 98
  • 134
1

Andy is right (in the comments): if the parent directory is itself the root directory of a parent repo, with all the subdirectories as submdules, then git status can detect any changes in one of them.

You can also use (with submodules) git diff

git submodule foreach --recursive git diff --name-status

Without submodules, see a scripting solution at "git: Find all uncommited locals repos in a directory tree".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Add this alias to your .gitconfig file and then you can run git status-all from a parent directory to get the status of all git repositories recursively.

[alias]
status-all = "!for d in `find . -name \".git\"`; do echo \"\n*** Repository: $d ***\" && git --git-dir=$d --work-tree=$d/.. status; done"
BrianV
  • 961
  • 8
  • 9
0

I don't think git has this build in, thus some time ago I created a script to do this: https://github.com/mnagel/clustergit

clustergit allows you to run git commands on multiple repositories at once. It is especially useful to run git status recursively on one folder. clustergit supports git status, git pull, git push, and more.

enter image description here

mnagel
  • 6,729
  • 4
  • 31
  • 66
0

In case someone needs a one liner:

rootdir=$(pwd);for folder in $(ls -p | grep /);do cd "$rootdir/$folder";git status; cd $rootdir; done
Endrit Demaj
  • 134
  • 6
0

Maybe https://metacpan.org/module/rgit might help :)

mithun
  • 316
  • 3
  • 3