Skip to content

Instantly share code, notes, and snippets.

@putermancer
Created November 2, 2010 16:36
Show Gist options
  • Save putermancer/659903 to your computer and use it in GitHub Desktop.
Save putermancer/659903 to your computer and use it in GitHub Desktop.
Quickly set up a shared git repository
REPONAME=${1%/} # trim trailing slash
if [ ! -d "$REPONAME" ]; then
# Make a temporary working directory
mkdir $REPONAME && cd $REPONAME
echo .DS_Store > .gitignore # ignore a common MacOS file
# make an initial commit
git init && git add .gitignore && git commit -m "initial commit"
else
# Assume this is a basic git repo that needs to be set up for sharing
cd $REPONAME
fi
# rename the "master" branch to "develop" and set up a "production" branch
# this is to prepare it for our git-flow workflow
git branch -m master develop
git branch production
# make a bare repo which can be shared
cd .. && git clone --bare $REPONAME $REPONAME.git
# remove the old directory and prep to make final changes for the shared repository
rm -rf $REPONAME && cd $REPONAME.git
# set some config variables to make sure git sets up file permissions correctly
# and disables non-fast-forward pushes (which change other people's history
# and are usually a bad idea)
git config core.sharedrepository true
git config receive.denyNonFastForwards true
# make filenames case sensitive
git config core.ignorecase false
# optionally (but recommended) enable the repo for explicit export by
# git-daemon and set up hooks used by web repo browsers
touch git-daemon-export-ok
mv hooks/post-update.sample hooks/post-update
# make sure permissions are all good
find objects -type d -exec chmod 02775 {} \;
# done
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment