Last active
December 29, 2021 14:03
-
-
Save npodonnell/a91fdd54614bf1756cf6e025845c4484 to your computer and use it in GitHub Desktop.
Quickly Make Git Repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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