1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# git-keeper
Works like etckeeper, but tracks git repos specified instead of just `/etc`.
No third-party dependencies required. Python >= 3.9 (as the one for Debian 11). It's expected for this script to run in supported Ubuntu LTS and Debian (5 years, ESM and ELTS excluded).
As `gitkeeper` conflicts with `mrb`, it's renamed to `git-keeper` now.
Available in [GitHub](https://github.com/taoky/git-keeper) and [Debian GitLab (Salsa)](https://salsa.debian.org/taoky/git-keeper).
## Install
### Debian install
You could download the `.deb` file from [Releases](https://github.com/taoky/git-keeper/releases/tag/rolling) page. And then install it with `apt` -- it has very minimal dependencies so it should install smoothly.
Note that it's recommended to remove `/usr/local/bin/gitkeeper` or `/usr/local/bin/git-keeper` if you have installed it manually before.
### Single file install
```shell
sudo wget https://github.com/taoky/git-keeper/raw/master/git-keeper -O /usr/local/bin/git-keeper
sudo chmod +x /usr/local/bin/git-keeper
sudo ln -s /usr/local/bin/git-keeper /usr/local/bin/git-kp
```
And then create `/etc/git-keeper.conf` with repos you need to track.
If you're using bash, you could download the completion script:
```shell
sudo wget https://github.com/taoky/git-keeper/raw/master/completions/git-keeper.completion.bash -O /etc/bash_completion.d/git-keeper
```
If you want to add motd, add following files:
```shell
sudo wget https://github.com/taoky/git-keeper/raw/master/motd/99-git-keeper -O /etc/update-motd.d/99-git-keeper
sudo chmod +x /etc/update-motd.d/99-git-keeper
sudo wget https://github.com/taoky/git-keeper/raw/master/motd/git-keeper-motd.service -O /etc/systemd/system/git-keeper-motd.service
sudo wget https://github.com/taoky/git-keeper/raw/master/motd/git-keeper-motd.timer -O /etc/systemd/system/git-keeper-motd.timer
sudo mkdir -p /etc/git-keeper.d
sudo wget https://github.com/taoky/git-keeper/raw/master/motd/motd-clean.tmpl -O /etc/git-keeper.d/motd-clean.tmpl
sudo wget https://github.com/taoky/git-keeper/raw/master/motd/motd-dirty.tmpl -O /etc/git-keeper.d/motd-dirty.tmpl
sudo systemctl enable --now git-keeper-motd.timer
```
## Help
```console
$ git-keeper help
usage: Track git repos [-h] [--config CONFIG] [--parallel PARALLEL] {status,commit,update,vcs,ls,diff,help} ...
positional arguments:
{status,commit,update,vcs,ls,diff,help}
status Show status of repo(s)
commit Add all and commit changes in repo(s) on behalf of current user
update Push/pull repo(s) with remote
vcs Run a git command on repo(s)
ls Just list all repos
diff Show changes in given repo
help Show help
options:
-h, --help show this help message and exit
--config CONFIG, -c CONFIG
Path to config file
--parallel PARALLEL, -p PARALLEL
Threads to use for status and update commands
```
`PARALLEL` defaults to 8.
A special name, `.`, could be used to represent the current directory repo if it exists in config file. This means that you could set `alias gitkp="git-keeper vcs ."` and enjoy `gitkp` same as how you use `git` before. Also, you could put a symlink named `gitkp` to `/usr/local/bin` pointing to `git-keeper`, and then use `gitkp` directly.
## Example

## Finding all git repos
```bash
sudo find / -name .git -type d -xdev 2>/dev/null
```
## Config example
### `/etc/git-keeper.conf`
```ini
[.config]
# .config is a special case that used to configure git-keeper itself
motd-template-dirty = /etc/git-keeper.d/motd-dirty.tmpl
motd-template-clean = /etc/git-keeper.d/motd-clean.tmpl
[rsyncd]
path = /etc/rsyncd
[systemd-network]
path = /etc/systemd/network
[repos]
path = /home/mirror/repos
user = mirror
```
By default git-keeper would try to get the owner of specified folder and use it as the user to run git. You can specify a user in the config file to override this.
### `~/.git-keeper.conf`
```ini
[user]
email = me@example.com
name = example
```
git-keeper would ask your email if the file does not exist, and use username as name. You could override them in the config file. If `~/.git-keeper.conf` does not exist, git-keeper would try reading `~/.gitconfig` to see if `user.email` is set, and use it and `user.name` (or username).
Note that if you use `sudo` to run git-keeper, it would still use the config file in the home directory of the user (instead of root) who runs it.
## Practice of SSH deploy key
git-keeper would not try to push repositories when it has a HTTP(S) remote (as you need to type in password/code in most cases). So you might what to use SSH deploy key.
However, GitHub does not support to use a same deploy key for multiple repositories. In this case you can create a deploy key for each repository:
1. Create a SSH key pair inside the `.git` directory of the repository.
```bash
cd .git
# RSA key pair
ssh-keygen -f ./id_rsa -t rsa -b 4096 -N ""
# or ED25519 key pair
ssh-keygen -f ./id_ed25519 -t ed25519 -N ""
```
2. Update `.git/config` like this:
```ini
[core]
# ...
# RSA key pair
sshCommand = ssh -i .git/id_rsa
# or ED25519 key pair
sshCommand = ssh -i .git/id_ed25519
```
3. Add public key (`id_rsa.pub` or `id_ed25519.pub`) to the repository's deploy keys.
|