Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active Dec 29, 2021
Embed
What would you like to do?
Quickly Make Git Repos
#!/usr/bin/env sh
# make-repo
# Creates a bare, named git repo on the server side
# N. P. O'Donnell, 2020 - 2021
REPO_BASE=/git
REPO_NAME=$1
REPO_DIR=$REPO_BASE/$REPO_NAME.git
HOSTNAME=$(hostname)
if [ -z $REPO_NAME ]; then
echo "Usage: $0 <repo name>"
exit 1
fi
if [ -d $REPO_DIR ]; then
echo "Repository already exists!"
exit 1
fi
sudo -u git mkdir -p $REPO_DIR
sudo -u git git init --bare $REPO_DIR
sudo -u git /usr/bin/env sh -c "echo $REPO_NAME > $REPO_DIR/description"
echo "Created repo $REPO_NAME in $REPO_DIR"
echo ""
echo "Update existing repo with:"
echo ""
echo "echo $REPO_NAME > .git/description"
echo "git remote add origin ssh://git@$HOSTNAME$REPO_DIR"
echo "git push --set-upstream origin \$(git branch | grep '^* ' | sed -e 's|^* ||')"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment