Skip to content

Instantly share code, notes, and snippets.

@conrad784
Created April 25, 2018 08:02
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 conrad784/133e99e980362ba24dc76175f3355c37 to your computer and use it in GitHub Desktop.
Save conrad784/133e99e980362ba24dc76175f3355c37 to your computer and use it in GitHub Desktop.
create a git repository on a ssh host
#!/bin/sh
GITHOST="myGit" # remote server name (for ssh)
REMOTE="myGit" # remote name in git config
GITFOLDER="git"
MYUSERNAME=$USER # assume we want to take current user account, change this at will
if [ -z "$1" ]; then
FOLDERNAME=$( basename $(pwd))
else
FOLDERNAME=$1
fi
REPO="/home/$MYUSERNAME/$GITFOLDER/$FOLDERNAME.git"
echo -n "Creating $GITHOST:$REPO (y/n)?"
read answer
if [ "$answer" != "${answer#[Yy]}" ]; then
if ! ssh $GITHOST "[ -d $REPO ]"; then
ssh $GITHOST "mkdir -p $REPO"
ssh $GITHOST "git init --bare $REPO"
git remote add $REMOTE $GITHOST:$REPO
else
echo "[ERROR] there is already a repository"
fi
else
echo "Aborting..."
fi
echo "Make $REMOTE default push remote:"
echo ""
echo "git push --set-upstream $REMOTE master"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment