Skip to content

Instantly share code, notes, and snippets.

@joelpurra
Created October 6, 2016 16:48
Show Gist options
  • Save joelpurra/fc703795653c82764858b42f6cc3fff8 to your computer and use it in GitHub Desktop.
Save joelpurra/fc703795653c82764858b42f6cc3fff8 to your computer and use it in GitHub Desktop.

Revisions

  1. Eike Kettner revised this gist Mar 26, 2012. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions git-create.bash
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    # create a new empty remote repository.
    #
    # Usage: git-create <remote-url>
    # works only with simple urls, not ssh://user@remote:port/path/to/repo
    #
    if [ -z "$1" ]
    then
    @@ -18,7 +17,7 @@ HOST=`echo $1 | tr ':' ' ' | cut -d' ' -f1`
    REPO=`echo $1 | tr ':' ' ' | cut -d' ' -f2`

    #append .git, if not already
    if [ ! `echo $PATH | grep -e '.git$'` ]
    if [ ! `echo $REPO | grep -e '.git$'` ]
    then
    REPO=$REPO.git
    fi
    @@ -32,8 +31,8 @@ then
    fi


    REMOTE_CMD="mkdir -p $PATH && git init --bare $PATH"
    ssh $HOST '$REMOTE_CMD'
    REMOTE_CMD="mkdir -p $REPO && git init --bare $REPO"
    ssh $HOST $REMOTE_CMD
    if [ $? -eq 0 ]
    then
    echo "Add content by pushing to the repository:"
    @@ -43,4 +42,4 @@ then
    echo
    else
    echo "Creating repository failed."
    fi
    fi
  2. Eike Kettner created this gist Mar 26, 2012.
    46 changes: 46 additions & 0 deletions git-create.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/bash
    #
    # create a new empty remote repository.
    #
    # Usage: git-create <remote-url>
    # works only with simple urls, not ssh://user@remote:port/path/to/repo
    #
    if [ -z "$1" ]
    then
    echo "Usage: $0 <remote-url>"
    echo
    exit 1
    fi


    #parse url in host and repository path
    HOST=`echo $1 | tr ':' ' ' | cut -d' ' -f1`
    REPO=`echo $1 | tr ':' ' ' | cut -d' ' -f2`

    #append .git, if not already
    if [ ! `echo $PATH | grep -e '.git$'` ]
    then
    REPO=$REPO.git
    fi

    echo "Create Repository $REPO at $HOST"
    if [ "$2" == "-i" ]
    then
    echo -n "? (y/n) "
    read r
    if [ $r == "n" ]; then exit 0; fi
    fi


    REMOTE_CMD="mkdir -p $PATH && git init --bare $PATH"
    ssh $HOST '$REMOTE_CMD'
    if [ $? -eq 0 ]
    then
    echo "Add content by pushing to the repository:"
    echo
    echo "git remote add origin $HOST:$REPO"
    echo "git push -u origin master"
    echo
    else
    echo "Creating repository failed."
    fi