Skip to content

Instantly share code, notes, and snippets.

@validatorru
Created October 12, 2016 12:59
Show Gist options
  • Save validatorru/6eac0f676958052f2c5da0d98e03448f to your computer and use it in GitHub Desktop.
Save validatorru/6eac0f676958052f2c5da0d98e03448f to your computer and use it in GitHub Desktop.
a hint on how we create git repositories
#!/bin/bash
# this is a hint on how we create git repositories at BUZZfriends
# this script is not tested and surely might not work as expected
if [ -z "$1" ]; then
echo usage: $0 project prefix and project directory prefix
exit
fi
PREFIX=$1
DOMAINNAME="YOURDOMAINNAME"
DIRECTORY=/var/www/$PREFIX.$DOMAINNAME/www/
# Directory should already exist
# so that we can add it to the first commit
echo "create .git folder"
mkdir /git/$PREFIX.git
cd $DIRECTORY
echo "initialise git in project directory"
git init
echo "add all files in project directory"
git add .
echo "commit all files"
git commit -m "Initial commit of $PREFIX"
echo "go back to .git folder"
cd /git/$PREFIX.git
echo "create --bare repository"
git --bare init
cd -
echo "add remote hub to project"
git remote add hub /git/$PREFIX.git/
git remote show hub
git push hub master
echo "push to hub"
git push hub master
cd /git/$PREFIX.git/hooks/
touch post-update
echo "#!/bin/sh" >> post-update
echo "echo" >> post-update
echo "echo Pulling changes into Prime [Hubs post-update hook]" >> post-update
echo "cd $DIRECTORY || exit" >> post-update
echo "unset GIT_DIR" >> post-update
echo "git pull hub master" >> post-update
chmod +x post-update
cd $DIRECTORY.git/hooks/
touch post-commit
echo "#!/bin/sh" >> post-commit
echo "echo" >> post-commit
echo "echo pushing changes to Hub [Primes post-commit hook]" >> post-commit
echo "echo" >> post-commit
echo "git push hub" >> post-commit
chmod +x post-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment