Last active
November 12, 2023 15:52
-
-
Save HarHarLinks/f3a333d6928cb2080d6f37475e23372c to your computer and use it in GitHub Desktop.
bash script that will pull all changes from one remote and push them to another
This file contains 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
#!/usr/bin/env bash | |
# the following hardcoded assumtions are made: | |
# - before running this script, you must locally checkout the source repo | |
# - set the source remote's name in the remote variable | |
# - create a target repo and add it to the local checkout with the name "mirror" | |
# - branch names containing "dependabot" and "renovate" are ignored | |
# - the repo must have a "default branch" called master, main, or develop which will be used in that order | |
remote=origin | |
root=$(pwd) | |
for repo in ./* | |
do | |
if [[ -d "$repo" ]] && [[ -e "$repo/.git" ]]; then | |
echo -e "\033[1;32mupdating $repo\033[0m" | |
cd $repo | |
echo -e "\033[1;32mdownloading new changes\033[0m" | |
git fetch $remote | |
echo -e "\033[1;32msetting branches to track $remote\033[0m" | |
for brname in `git branch -r | grep $remote | grep -v /master | grep -v /HEAD | grep -v dependabot | grep -v renovate | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'` | |
do | |
git branch --track $brname $remote/$brname || true | |
done | |
(git checkout master && git branch -u $remote/master) || \ | |
(git checkout main && git branch -u $remote/main) || \ | |
(git checkout develop && git branch -u $remote/develop) | |
echo -e "\033[1;32mupdating local branches\033[0m" | |
git pull -v | |
echo -e "\033[1;32mpushing changes to mirror\033[0m" | |
for brname in `git branch -l | grep -v dependabot | grep -v renovate | sed 's/^[* ] //gm'` | |
do | |
# echo -e "\033[1;32mpushing $brname...\033[0m" | |
git push -u mirror $brname | |
done | |
git push -u mirror --tags | |
echo -e "\033[1;32mupdated $repo\033[0m" | |
cd $root | |
echo "" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment