Last active
February 6, 2021 16:29
-
-
Save npodonnell/dd13d327c58d1f913bff142601c781e1 to your computer and use it in GitHub Desktop.
Renames a named git repo on the server side
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
| #!/usr/bin/env sh | |
| # rename-repo | |
| # Renames a named git repo on the server side | |
| # N. P. O'Donnell, 2020 | |
| REPO_BASE=/git | |
| REPO_OLD_NAME=$1 | |
| REPO_NEW_NAME=$2 | |
| REPO_OLD_DIR=$REPO_BASE/$REPO_OLD_NAME.git | |
| REPO_NEW_DIR=$REPO_BASE/$REPO_NEW_NAME.git | |
| HOSTNAME=$(hostname) | |
| if [ ! -d $REPO_OLD_DIR ]; then | |
| echo "Repository not found!" | |
| exit 1 | |
| fi | |
| sudo -u git mv $REPO_OLD_DIR $REPO_NEW_DIR | |
| sudo -u git /usr/bin/env sh -c "echo $REPO_NEW_NAME > $REPO_NEW_DIR/description" | |
| echo "Renamed $REPO_OLD_NAME to $REPO_NEW_NAME" | |
| echo "To update on downstream remotes run:" | |
| echo "" | |
| echo "git remote set-url origin ssh://git@$HOSTNAME$REPO_NEW_DIR" | |
| echo "echo $REPO_NEW_NAME > .git/description" | |
| echo "mv ../$REPO_OLD_NAME ../$REPO_NEW_NAME && cd ../$REPO_NEW_NAME" | |
| echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment