Skip to content

Instantly share code, notes, and snippets.

@nicc777
Created May 3, 2026 14:41
Show Gist options
  • Select an option

  • Save nicc777/c9d958d9136ed8a18a59fb5903899397 to your computer and use it in GitHub Desktop.

Select an option

Save nicc777/c9d958d9136ed8a18a59fb5903899397 to your computer and use it in GitHub Desktop.
Script for provisioning new Git repo on a private host
#!/bin/bash
read -p "Enter the new Git repo name: " REPO_NAME
if [ -d "$REPO_NAME" ]; then
echo "A repository named '$REPO_NAME' already exists."
exit 1
else
echo "Creating new repo '$REPO_NAME'..."
fi
BARE_REPO_PATH="/home/git/${REPO_NAME}"
WORKING_REPO_PATH="/tmp/${REPO_NAME}-working"
TEST_PATH="/tmp/${REPO_NAME}-clone"
cd /home/git
echo "Creating bare repository at $BARE_REPO_PATH..."
git init --bare --initial-branch=main "$BARE_REPO_PATH"
echo "Creating working repository at $WORKING_REPO_PATH..."
mkdir -p "$WORKING_REPO_PATH"
cd "$WORKING_REPO_PATH" || exit
git init --initial-branch=main
echo "# Initial README" > README.md
git add README.md
git commit -m "Initial commit"
git remote add origin "$BARE_REPO_PATH"
git push origin main
echo "Cloning from bare repo to $TEST_PATH..."
cd /tmp || exit
git clone "$BARE_REPO_PATH" ${REPO_NAME}-clone
cd ${REPO_NAME}-clone || exit
echo "Current branch after clone:"
git branch --show-current
echo "==============================================================================="
echo
echo " git clone git@git.your-hostname.com:${REPO_NAME}"
echo
echo "==============================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment