Skip to content

Instantly share code, notes, and snippets.

@dhhdev
Created March 13, 2016 02:55
Show Gist options
  • Save dhhdev/7c9d2465d62e19a5f27a to your computer and use it in GitHub Desktop.
Save dhhdev/7c9d2465d62e19a5f27a to your computer and use it in GitHub Desktop.
Create a repository on remote server and start hacking!
#!/bin/bash
## Start repository on own Git Server and start hacking.
## Yes, it could be way better - detection of already made repository, etc.
## Usage: git-create.sh <reponame> "<description>"
## Never use slashes!
# Connection
HOST='git'
USER='git'
# Paths
LOCAL_PATH=${PWD}
REMOTE_PATH='/repos'
# Repo Variables
REPO_NAME=$1
REPO_DESCRIPTION=$2
echo "-------------------------------------------"
echo "------ Building New Git Repository --------"
echo "-------------------------------------------"
echo "--"
echo "-- Creating bare remote repo at:"
echo "-- $USER@$HOST/$REMOTE_PATH/$REPO_NAME"
echo "--"
# Create and configure remote repository
ssh $USER@$HOST 'mkdir '$REMOTE_PATH'/'$REPO_NAME' && cd '$REMOTE_PATH'/'$REPO_NAME' && git --bare init && git --bare update-server-info && cp hooks/post-update.sample hooks/post-update && chmod a+x hooks/post-update && touch git-daemon-export-ok && echo "'$REPO_DESCRIPTION'" > description'
# Create local repository and push first commit (README.md) to repository
echo "--"
echo "-- Initializing local repo & pushing to remote"
echo "--"
echo "# $REPO_NAME" > README.md
git init
git add .
git commit -m 'Initial commit'
git push --all $USER@$HOST:$REMOTE_PATH/$REPO_NAME
git remote add origin $USER@$HOST:$REMOTE_PATH/$REPO_NAME
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git fetch
git merge master
git branch -a
echo "--"
echo "-- Your new git repo '$REPO_NAME' is ready and initialized at:"
echo "-- $USER@$HOST/$REMOTE_PATH/$REPO_NAME"
echo "-- Happy hacking!"
echo "--"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment