Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active February 6, 2021 16:29
Show Gist options
  • Select an option

  • Save npodonnell/dd13d327c58d1f913bff142601c781e1 to your computer and use it in GitHub Desktop.

Select an option

Save npodonnell/dd13d327c58d1f913bff142601c781e1 to your computer and use it in GitHub Desktop.
Renames a named git repo on the server side
#!/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