Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Created September 29, 2010 17:07
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 chrismytton/603122 to your computer and use it in GitHub Desktop.
Save chrismytton/603122 to your computer and use it in GitHub Desktop.
`gitify(1)` your remote repository
#!/bin/sh
# Get a website ready to deploy with git
REPO_HOST='example.com'
REPO_PATH=$HOME/repos
# Check that the user has provided a directory to use and it exists
if [ ! "$1" ]; then
echo "Usage: $0 DIRECTORY"
echo "Where DIRECTORY is the folder that you want to contain the working copy"
exit 0
fi
# Allow environment variables to override defaults at the top of the script
if [ $GITIFY_REPO_PATH ]; then
REPO_PATH=$GITIFY_REPO_PATH
fi
# Test if the directory exists
if [ ! -d "$1" ]; then
# Create the directory
mkdir $1
# Check that the directory was created successfully
if [ ! $? -eq 0 ]; then
exit 1
fi
fi
# Ask for a repo name
echo -n "Repository name (no spaces): " && read name
git init --bare $REPO_PATH/$name.git/ && cd $HOME/repos/$name.git/
# Configure the git repo to be pushable to
git config core.worktree $1
git config core.bare false
git config receive.denycurrentbranch ignore
# Create the post-receive hook and make it executable
echo "#!/bin/sh
git checkout -f" > hooks/post-receive
chmod +x hooks/post-receive
remote_repo="$USER@$HOSTNAME:repos/$name.git"
gra="git remote add webserver $remote_repo"
gpwm="git push webserver master"
# Give the user some information about using their new repository
echo
echo "# You now need to push your branch to the new repository"
echo "#"
echo "# $remote_repo"
echo "#"
echo "# To add as a remote run the following on your local computer"
echo "# $gra"
echo "#"
echo "# Then to push to the new repository"
echo "# $gpwm"
echo "#"
echo "# Note: you don't have to call the remote 'webserver'."
echo "#"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment