Skip to content

Instantly share code, notes, and snippets.

@idhamhafidz
Forked from ckalima/remgit.sh
Created January 6, 2016 17:21
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 idhamhafidz/83cb5f644103e35914cd to your computer and use it in GitHub Desktop.
Save idhamhafidz/83cb5f644103e35914cd to your computer and use it in GitHub Desktop.
Shell Script to Create a Remote Git Repository
# remgit.sh
# Creates a remote git repository from the current local directory
# Configuration
# Replace SSH_USERNAME, SSH_HOST, SSH_GIT_PATH with your details
USER=SSH_USERNAME
HOST=SSH_HOST
GIT_PATH=SSH_GIT_PATH
REPO=${PWD##*/}
GIT_REMOTE_URL=ssh://$USER@$HOST/$GIT_PATH/$REPO
echo "-------------------------------------------"
echo "------ Building New Git Repository --------"
echo "-------------------------------------------"
# Setup remote repo
echo "--"
echo "-- Creating bare remote repo at:"
echo "-- $USER@$HOST/$GIT_PATH/$REPO"
echo "--"
ssh $USER@$HOST 'mkdir '$GIT_PATH'/'$REPO' && cd '$GIT_PATH'/'$REPO' && 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'
# Configure local repo
echo "--"
echo "-- Initializing local repo & pushing to remote"
echo "--"
touch .gitignore
git init
git add .
git commit -m 'initial commit'
git push --all $GIT_REMOTE_URL
git remote add origin $GIT_REMOTE_URL
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' is ready and initialized at:"
echo "-- $USER@$HOST/$GIT_PATH/$REPO"
echo "--"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment