Skip to content

Instantly share code, notes, and snippets.

@cacharle
Created July 20, 2020 04:28
Show Gist options
  • Save cacharle/0b68c6238f83a0568f566516617901a6 to your computer and use it in GitHub Desktop.
Save cacharle/0b68c6238f83a0568f566516617901a6 to your computer and use it in GitHub Desktop.
Change remote url of repository for username change
#!/bin/sh
[ $# -eq 0 ] && echo "Usage $0 REPOSITORY ..." && exit 1
for repo in $@; do
if [ ! -d $repo ] || [ ! -d $repo/.git ]; then
echo "$repo: Is not a repository"
continue
fi
cd $repo
origin_url=`git remote get-url origin`
if [ $? -ne 0 ]; then
echo "$repo: No remote named origin"
cd ..
continue
fi
url=`echo $origin_url | sed 's/HappyTramp/cacharle/'`
echo "$repo: Changing remote url to: $url"
git remote set-url origin $url
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment