Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active December 29, 2021 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npodonnell/a91fdd54614bf1756cf6e025845c4484 to your computer and use it in GitHub Desktop.
Save npodonnell/a91fdd54614bf1756cf6e025845c4484 to your computer and use it in GitHub Desktop.
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