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

khoomeister
  • 4,206
  • 4
  • 26
  • 38
  • 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

4 Answers4

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,042,979
  • 435
  • 3,649
  • 4,283
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
  • 746
  • 6
  • 8
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
  • 5,938
  • 4
  • 25
  • 63
0

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

mithun
  • 316
  • 3
  • 3