thegeeklab/content/posts/2021/toolbox-2-git-plus/index.md

2.7 KiB

title date authors tags resources
Toolbox 2: git-plus 2021-06-19T09:50:00+01:00
robert-kaussow
Sysadmin
Automation
name src params
feature images/feature.jpg
anchor credits
Center [Fleur](https://unsplash.com/@yer_a_wizard) on [Unsplash](https://unsplash.com/photos/dQf7RZhMOJU)

If you work with a lot of Git repositories on a regular basis, you're bound to run into the situation where you need to make changes to multiple repositories sooner or later. While it would be possible to run your Git commands in a shell loop over everything repositories, it is often tedious to type the command or remember the correct syntax.

This is where git-plus comes into play. It is a small collection of Git utilities that tries to simplify some common tasks:

  • git multi execute a single Git command on multiple Git repositories
  • git relation show a relation between two branches/commits/tags
  • git old-branches find old/unused branches
  • git recent list branches ordered by last commit time
  • git semver lists and creates Git semver (semantic versioning) tags

But there is one command that I use every day now, git multi. The command works folder based, that means you have to have all target repositories in one directory. There is no grouping feature at the moment, if you want to group some repositories you would have to use multiple sub-directories. Since I also use direnv, this folder-based workflow works very well for me. Repositories can be temporarily excluded with the CLI flag -e reponame or by a .multigit_ignore file in the parent directory. Basically git multi executes normal Git commands and is therefore quite easy to use. One example where the tool helps me is when I need to adjust the CI configuration in multiple repositories, for example. Only a few steps are needed for this:

  • Create a new branch:
    git multi checkout -b "replace-ci-step"
  • Use your favorite search and replace tool to add your changes to all repositories
  • Create a commit:
    git multi add -A; git multi commit -m "ci: replace broken step in ci config"
  • Finally push your new branch:
    git multi push origin replace-ci-step

That's it. Simple, isn't it? Of course it doesn't work in all cases, especially for more complex and repository specific changes it's getting harder, but for generic changes like CI configurations, the current year in a copyright string or a license file or globally used badges in the readme it's really straight forward.

git-plus is written in Python and available on PyPi.