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

44 lines
2.7 KiB
Markdown
Raw Normal View History

2021-06-19 08:53:37 +00:00
---
title: "Toolbox 2: git-plus"
date: 2021-06-19T09:50:00+01:00
authors:
- robert-kaussow
tags:
- Sysadmin
- Automation
resources:
- name: feature
src: "images/feature.jpg"
params:
anchor: Center
credits: >
[Fleur](https://unsplash.com/@yer_a_wizard) on
[Unsplash](https://unsplash.com/photos/dQf7RZhMOJU)
---
2021-06-19 09:05:00 +00:00
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.
2021-06-19 08:53:37 +00:00
<!--more-->
This is where [git-plus](https://github.com/tkrajina/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](/posts/toolbox-2-git-plus/), 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
2021-06-20 20:18:50 +00:00
- Create a commit: \
2021-06-19 08:53:37 +00:00
`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](https://pypi.org/project/git-plus/).