Gongey’s BlogDescribing the Indescribable World of The Gongey

All things Gongey

A Gongey is a special being. Having been created in the fiery furnaces of hell...wait...let me start over.
Back when collars were huge and pants were in the shape of bells I was born. The year was 1977. After 10 long months of gestation I was ready to join the world and make my contribution.
This blog is a record of my life. Good, bad and generally mundane!

This is more for my own notes, as I was completely confused on how to setup a Git repository.
NOTE: I have updated the process I use, please see the UPDATED section below.
The best resource I found was from http://blog.mornati.net.

Here is the blog entry from mmornati:
*Source: https://blog.mornati.net/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:
newgit()
{
if [ -z $1 ]; then
echo "usage: $FUNCNAME project-name.git"
else
gitdir="/home2/mornatin/repositories/$1"
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
popd
fi
}

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.

UPDATED USAGE

**Update 05/10/2016**
When I setup a git repository on Bluehost/Hostmonster I only use the code below.

You will need to have SSH enabled on your Bluehost account.
Login using SSH(I use PuTTY Client), follow the steps below:


mkdir /NAMEOFGITDIRECTORY
pushd /NAMEOFGITDIRECTORY
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
popd

After I have completed the steps above I PUSH my initial COMMIT to the server.

This entry was posted in General, Programming and tagged , . Bookmark the permalink.

5 Responses to Setup Git Repository on Bluehost

  1. Pingback: Github Repository on Remote Host | Techne

  2. Mike Z says:

    Thanks for posting this. I know it’s been a few years since you did, but this appears to be the source Google refers searchers like me to. In your updated usage, do you mean to say that that code block should be encapsulated as the body of the `newgit()` function you store in .bashrc, and then we should follow the rest of the instructions from your original post? Or should most of the content be ignored and the ‘updated usage’ be used exclusively? Thanks! /mz

  3. Gongey says:

    Great question. After reading the post again I can see how that could be confusing.

    I no longer use the bash function/command and only use the “Updated Usage” code:


    mkdir /NAMEOFGITDIRECTORY
    pushd /NAMEOFGITDIRECTORY
    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
    popd

    When I add the remote I use the following command:
    (typed all on one line, the WP Theme is wrapping the text)

    git remote add origin ssh://user@yourdomain.com:22/nameofgitdirectory/nameofgitfile.git

    Hopefully that helps!

  4. Gongey says:

    Awesome thanks! The link has been updated.

Leave a Reply

Your email address will not be published. Required fields are marked *

Browse by Topic