Last active
May 20, 2025 17:16
-
-
Save simon-brooke/41e185478ff9ca1891490eb4b7ebdd6b to your computer and use it in GitHub Desktop.
Moving a lot of projects off GitHub
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 | |
# Script to set all origin URLs of all my projects in my workspace to the new | |
# (forgejo) URL, replacing previous GitHub URLs. | |
# Background: I keep all my active projects as subdirectories of the | |
# directory `workspace`. You need to clone all the projects from GitHub to | |
# Forgejo **first**, before running this script; but this is simply done | |
# through the Forgejo user interface. See | |
# https://www.journeyman.cc/blog/posts-output/2025-03-08-installing-forgejo/ | |
# Variables in capitals you can think of as configuration -- you will want | |
# to change these to account for the difference between your setup and mine | |
WORKSPACE=~/workspace | |
GHUSERNAME="simon-brooke" | |
GHURL="[email protected]:${GHUSERNAME}/" | |
FJUSERNAME="simon" | |
FJSSHPORT="1234" | |
FJURL="ssh://[email protected]:${FJSSHPORT}/${FJUSERNAME}/" | |
pushd "$WORKSPACE" | |
for project in * | |
do | |
if [ -d $project ] | |
then | |
pushd $project | |
origin=`git remote -v | grep '^origin' | head -1 | awk '{print $2}'` | |
echo "Project = ${project}; origin = ${origin}" | |
echo $origin | grep "${GHURL}" | |
if [ $? -eq 0 ] | |
then | |
# Is it one of mine or my fork of someone else's? | |
git remote -v | grep '^upstream' | |
if [ $? -eq 0 ] | |
then | |
echo "...fork!" | |
else | |
echo "...mine!" | |
# I really ought to check that the directory name and the | |
# repository name are identical, but all mine are. | |
echo "Setting remote origin URL to ${FJURL}${project}" | |
git remote set-url origin ${FJURL}${project} | |
git fetch origin | |
git remote -v | grep '^github' | |
if [ $? -eq 0 ] | |
then | |
echo "... github remote already set up for ${project}, not altering" | |
else | |
git remote add github ${origin} | |
fi | |
fi | |
fi | |
popd | |
fi | |
done | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment