post: toolbox-2-git-plus
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Robert Kaussow 2021-06-19 10:53:37 +02:00
parent 252a938f18
commit 5bcbc100bd
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
3 changed files with 47 additions and 0 deletions

View File

@ -36,3 +36,7 @@ x86
systemd
Golang
[D|d]irenv
semver
CLI
PyPi
readme

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

View File

@ -0,0 +1,43 @@
---
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)
---
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.
<!--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
- Create a commit and push the new branch: \
`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/).