Created
April 25, 2018 08:02
-
-
Save conrad784/133e99e980362ba24dc76175f3355c37 to your computer and use it in GitHub Desktop.
create a git repository on a ssh host
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
#!/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