/ bluehost

Create Git repository on shared host

After the installation of git on my bluehost account I tried to figure out a good way to create and access to my git repository. Even if I thought the Apache bridge was the best way to access to git files, I found that on bluehost, the best and fastest way is directly using the ssh protocol.

So here explained the method I choose to create and use a private git repository on my shared account.

First of all, to simplify the repository creation process I added to .bashrc file a new function:

   if [ -z $1 ]; then
       echo "usage: $FUNCNAME project-name.git"
       mkdir $gitdir
       pushd $gitdir
       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

The operations to execute every time (and done automatically by the previous function) are:

  • create the project folder
  • initialize a git bare repository
  • update-server-info to update your git config file
  • enable the default post-update hook
  • create a file to enable the export of the bare repository
Now to create your repository you can simply run on the server:
 newgit test.git
and a test.git repository is created in your default location (defined in the bashrc function). To test it you can simply try to clone repository on your "development" machine:
 mmornati-macbook:~ mmornati$ git clone ssh://mornatin@mornati.net/~/repositories/test.git
Errors? If the response is no.... DONE! :)

The only things to remember is that the first commit on your project (test.git in this example), requires the specification of branch you want to work with, so you need to run commands like the following:

 touch README
git add .
git commit -m "Init repo"
git push -u origin master

The important thing is just the line with push. After this first commit/push you can work normally using git pull and git push and all your files will be sent on master branch of your repository.