Skip to content

Instantly share code, notes, and snippets.

@qixiaobo
Forked from samirreza/changeRemoteUrl.sh
Created June 1, 2022 09:41
Show Gist options
  • Save qixiaobo/62134ad3cff164c85854a439786621ef to your computer and use it in GitHub Desktop.
Save qixiaobo/62134ad3cff164c85854a439786621ef to your computer and use it in GitHub Desktop.
Shell script to bulk change git remote url
directoryContainingAllRepos="" # directory containing all git repo's
oldGitRemoteServer="" # current remote server url for example gitlab.com
newGitRemoteServer="" # new remote server url for example git.example.com
cd $directoryContainingAllRepos
find * -maxdepth 0 -type d \( ! -name . \) -print | while read dir
do
cd $dir
if [ -d ".git" ]
then
remoteUrl1="$(git config --get remote.origin.url)"
# echo "${remoteUrl1}"
remoteUrl2=${remoteUrl1/$oldGitRemoteServer/$newGitRemoteServer}
remoteUrl3=${remoteUrl2/-module}
git remote set-url origin ${remoteUrl3}
fi
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment