Chris
Chris

Reputation: 4774

Is there any functionality in git to check multiple git repos under a directory?

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

Upvotes: 2

Views: 1646

Answers (7)

Li Ge
Li Ge

Reputation: 11

I shared exactly the same concern when I run some machine learning experiments using multiple editable research repositories. I found sometimes it is quite hard and time-consuming to reproduce old experiments due to updates of repositories.

So I wrote a small tool Git_Repos_Tracker to track the versions and enforce all tracked repos to be clean when I run experiments, see example . It can detect if a debugger is used when run experiment. In this case it will tolerate to dirty repositories (unstaged and uncommited changes).

So everytime when I finish an experiment, I store the commit numbers of all repos in my log file see example. I can easily share these numbers with my colleagues and students, allowing them to easily reproduce my experiment.

Upvotes: 1

Endrit Demaj
Endrit Demaj

Reputation: 134

In case someone needs a one liner:

rootdir=$(pwd);for folder in $(ls -p | grep /);do cd "$rootdir/$folder";git status; cd $rootdir; done

Upvotes: 0

nos
nos

Reputation: 20862

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)

Upvotes: 1

mnagel
mnagel

Reputation: 6854

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

Upvotes: 0

BrianV
BrianV

Reputation: 1496

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"

Upvotes: 0

mithun
mithun

Reputation: 316

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

Upvotes: 0

VonC
VonC

Reputation: 1323573

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".

Upvotes: 1

Related Questions