Last active
August 29, 2015 13:56
-
-
Save searls/8798116 to your computer and use it in GitHub Desktop.
Handy script when you're moving a git repo from one github owner 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
#!/bin/bash -e | |
# Usage: | |
# $ git chown <repo name> <old owner> <new owner> | |
# Example: | |
# $ git chown lineman testdouble linemanjs | |
REPO_NAME=$1 | |
OLD_OWNER=$2 | |
NEW_OWNER=$3 | |
SED_PATTERN="s/$OLD_OWNER\/$REPO_NAME/$NEW_OWNER\/$REPO_NAME/g" | |
echo "--> searching for '$OLD_OWNER/$REPO_NAME' and replacing with '$NEW_OWNER/$REPO_NAME'" | |
git grep -l "$OLD_OWNER/$REPO_NAME" | xargs sed -i .gitchownbk "$SED_PATTERN" | |
echo "--> altering any git remotes' URLs" | |
sed -i .gitchownbk "$SED_PATTERN" .git/config | |
echo "--> cleaning out sed's backup files (*.gitchownbk)" | |
find . -name "*.gitchownbk" | xargs rm | |
echo "--> remaining references to '$OLD_OWNER' in repo:" | |
git grep "$OLD_OWNER" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment