#!/bin/sh # Helper script for git-shell to initialize bare repositories # Usage: ssh code@host init-repo [description] if [ $# -lt 1 ]; then echo "Usage: init-repo [description]" echo "Example: init-repo myproject.git" echo "Example: init-repo myproject.git 'A repo with foo'" exit 1 fi REPO_NAME="$1" shift DESCRIPTION="$*" # Ensure it ends with .git case "$REPO_NAME" in *.git) ;; *) REPO_NAME="${REPO_NAME}.git" ;; esac REPO_DIR="$HOME/$REPO_NAME" if [ -e "$REPO_DIR" ]; then echo "Error: Repository '$REPO_NAME' already exists" exit 1 fi echo "Initializing bare repository: $REPO_NAME" git init --bare --initial-branch=main "$REPO_DIR" # Add description if provided if [ -n "$DESCRIPTION" ]; then echo "$DESCRIPTION" > "$REPO_DIR/description" echo "Description set: $DESCRIPTION" fi echo "Repository initialized at: $REPO_DIR" echo "You can now push to it with: git remote add origin ssh://code@host/$REPO_NAME"