tags:

views:

503

answers:

4

Setting up a project is easy in git and so I can have separate repository even for small script. Now the problem is how to manage them.

I work in multiple places with these repositories. When I have done changes to some repository, I want to be able to update the repositories in other places.

So I have a directory with many repositories in it.

  1. How can I fetch all of them?
  2. How can I check whether any of them have uncommitted changes?
  3. How can I check whether any of them have changes to merge?

And it would be nice to be able to do these with one command.

The output needs to be silent enough to actually notice the things to do.

+4  A: 

You could try using repo with a custom manifest.xml file to specify where your repositories are. There is some documentation on how to do this.

Alternatively you could use git-submodule(1).

Spoike
git-submodule would be good, if I would want to keep the repositories at the exact same state, but that is not the case. The set of repositories is not the same in each place. There could be uncommitted changes. There could be changes I don't want to merge yet.
iny
I didn't know about git-submodule. Thanks for mentioning it.
sykora
Documentation for repo is quite minimal and looks like it is intended for different kind of work flow I want to use.
iny
A: 

You should check out rgit on the CPAN which recursively executes git commands on all repositories in a directory tree.

From the docs:

This utility recursively searches in a root directory (which may be the current working directory or - if it has been set - the directory given by the GIT_DIR environment variable) for all git repositories, sort this list by the repository path, chdir into each of them, and executes the specified git command.

Brian Phillips
A: 

Looks like writing a script to do it is quite easy. Essentially it needs to iterate over the repositories and then use commands like git ls-files, git diff and git log.

iny
I know it's late, but could you publish the script?
l0b0
There is no "the script". I'm using a script that I have written for my own needs, but it is not generic.
iny
+1  A: 

I use this script to easily execute git commands in all of my repositories.

#!/bin/sh
if [ ! "$1" = "" ] ; then

   if [ "$GITREPO" = "" -a -d "$HOME/cm/src" ] ; then
      GITREPO="$HOME/cm/src"
   fi

   if [ "$GITREPO" != "" ] ; then

      echo "Git repositories found in $GITREPO"
      echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-"

      DIRS="`/bin/ls -1 $GITREPO`"

      for dir in $DIRS ; do

         if [ -d $GITREPO/$dir/.git ] ; then
            echo "$dir -> git $1"
            cd $GITREPO/$dir ; git $@
            echo
         fi

      done
   else

      echo "Git repositories not found."

   fi
fi

By default the script will look for git repositories in ~/cm/src but you can override this by setting the GITREPO environment variable to your liking.

This script is based on this script.

Scotts