Last active
March 10, 2022 12:31
-
-
Save hypest/7596a5156396601a8d89d2af91577f14 to your computer and use it in GitHub Desktop.
Update git mirrors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Assume the clone-from-mirror.sh script is alongside the mirrors folders | |
| # get the folder of the script itself (from https://stackoverflow.com/a/246128) | |
| SOURCE=${BASH_SOURCE[0]} | |
| while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink | |
| DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) | |
| SOURCE=$(readlink "$SOURCE") | |
| [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located | |
| done | |
| SCRIPT_DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) | |
| # clone from the mirror | |
| git clone $SCRIPT_DIR/$1 $1 | |
| cd $1 | |
| # pull the submodules as well | |
| git submodule update --init --recursive | |
| # adds a "local-mirror" remote to point to the local filesystem mirror | |
| git remote add local-mirror `git remote get-url origin` | |
| # revises the "origin" remote to point to the real remote one instead of the local mirror it got cloned from | |
| git remote set-url origin `git --git-dir \`git remote get-url local-mirror\` remote get-url origin` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Update a folder with multiple git mirrors created with `git clone --mirror https://github.com/exampleuser/repository-to-mirror.git` | |
| find . -type d -depth 2 -exec sh -c 'cd "{}"; pwd; git remote update;' \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment