This site is now 100% read-only, and retired.

Easily working with multiple repositories (git, hg, etc)

Posted by Steve on Sun 8 Feb 2015 at 18:00

There are situations where it is ueful to checkout multiple repositories, which might use different revision control systems, and operate upon them as a group. This is what the mr tool was designed for.

The mr tool allows you to operate upon multiple repositoresi, regardless of whether they use git, mercurial, bzr, darcs, etc.

To get started you would first install the tool.

~# aptitude install mr

Once installed you can register the repositories you might have cloned by changing to their directories and running "mr register". For example I want to ensure that ~/git/dotfiles.git is registered:

~$ cd git/dotfiles.git
~/git/dotfiles.git $ mr register
Registering git url: git@github.com:skx/dotfiles.git in /home/skx/.mrconfig

At that point you can see this has been recorded in ~/.mrconfig:

[git/dotfiles.git]
checkout = git clone --bare 'git@github.com:skx/dotfiles.git' 'dotfiles.git'

Lets go a step further and register every git repository we have checked out beneath our home directory:

for i in $(find ~/ -name '.git' -type d -print); do mr register $(dirname $i); done

The end result will be that you'll have a lot of entries recorded in ~/.mrconfig and now you can update all those repositories via:

~$ cd
~$ mr update

If you're inside a repository then any mr operation will only apply to that one, but otherwise it will apply to all repositories, so you can pull/push easily on all repositories.

What I find most useful is for copyingthe state of multiple repositories amongst different machines. I like to have dotfiles, etc, checked out in the same location on all systems. Similarly the golang programming setup tends to involve cloning a lot of repositories to build libraries, etc, and it is useful to be able to record that easily.

If you sync your .mrconfig file you can checkout all repositories on a new system via a simple:

~$ mr checkout

Beyond that though you can write shell-snippets in your configuration file, to setup mirros etc. As a simple example I have this configured:

[Repos/yawns]
checkout = git clone 'ssh://skx@git.steve.org.uk/yawns/yawns.git' 'yawns'
                  cd yawns &&
                  git remote add github git@github.com:skx/yawnsns.git

This clones from one source, on git.steve.org.uk, then also adds a remote to allow me to mirror to github.com.

The example files located beneath /usr/share/doc/mr/examples demonstrate other tricks, such as cloning from github anonymously or via SSH, depending on the local hostname.