A little git mirror tutorial

On a linux device you can run the following to initialize a repo in a mirror

```

mkdir

cd mkdir

git clone --mirror #ssh or https should work

```

Note: specifying --mirror is important because it creates a bare repo that can be updated by git with a single command later.

You can run this script in the top level directory and it will recursively sync all of your --mirror repos. It will find all the directories that end in .git which is what happens when using the --bare or --mirror option during a clone.

```

#! /bin/sh

set -x

for DIR in $(find . -type d -name "*.git"); do

echo "Updating repo $DIR"

pushd "$DIR"

git remote update --prune # fails with or without this line

popd

done

```

If you a running a distro that uses systemd you can configure a systemd timer to run the sync script on a schedule to keep your repo synced with the upstream repo

Here is a tutorial I like, it's very hand-holding

https://documentation.suse.com/smart/systems-management/html/systemd-working-with-timers/index.html

Otherwise you can use cron assuming your distro has that option. I prefer systemd timers though :)

Finally, you can serve this directory using apache, nginx or whatever flavor http server you want.

Reply to this note

Please Login to reply.

Discussion

No replies yet.