Installing Git on Godaddy

& so I was sitting and pondering upon which revision control system I should deploy for an ongoing project, seeing that I’ll be needing someone to work on my application UI design in the near future, when my good friend Sola Ajayi, an avid & well matured developer swayed me towards Git. After much persuasion on the benefits, I decided to give it a go, and I’m certainly glad I did.

So what is Git?

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is used for version control of files, much like tools such as Mercurial, Bazaar, Subversion, CVS, Perforce, and Team Foundation Server.

- Git-scm.com

Scenario:

I have a shared dedicated hosting plan with Godaddy.com, while my actual development files are local on my system. I needed a scenario where once i’m done with a web-dev session, I would only upload files I modified and keep track of those changes rather than the whole project.

What you need:

  1. A GoDaddy hosting account: Obviously this tutorial assumes you have a GoDaddy hosting account or you intend to use one. The steps described below in installing Git are unique to GoDaddy because they use CentOS 5 linux operating system [at least my hosting account uses that]. so it will only work on other hosting servers if they are similar to GoDaddy’s configuration.
  2. Some Git knowledge: If you don’t have any experience or knowledge you can find some in their Community Book.
  3. Git installed: You need git installed on your local machine: Download from Git Website.
  4. SSH client: Hopefully if you installed properly from step 3 above you should have this installed.
  5. Bash shell on local machine: Same as step 4.

Setup Git on GaDaddy

As you know, Git is not installed on GoDaddy by default, and since the assumption is that you don’t have root access you’ll have to copy pre-complied binaries for CentOS 5 provided below to your hosting account on GoDaddy, so lets get cracking.
  • Step One: Enable SSH for your GoDaddy hosting account. GoDaddy documentation can be found on their help pages. Note that it takes some time for SSH access to come up, once its up you may proceed.
  • Step Two: Make sure you have at least one FTP account created.
  • Step Three: Setup password-less authentication using Public/Private keys on your ssh account. Here’s a tutorial if you need help:  Password-less SSH
  • Step Four: Use Git Bash Shell [Should be in you programs line up] Connect to your ssh account using the following:
    ssh username@domain.com

    Use your ftp user login as “username” and the hosting account domain as “domain”. If it’s your first time connecting via ssh, it should ask you to add the domain to the list of know hosts, type yes and continue.

  • Step Five: Download the git binaries to your GoDaddy account by running the following command:
    wget http://iamchuka.com/downloads/git-1.7.3.4_centos5.2.tar.bz2

    These binaries were compiled from the GIT (version 1.7.3.4) on a linix machine running CentOS 5.2, which is the same operating system that my GoDaddy hostng account is running. Usually, linux binaries are relatively portable so these might also work on other servers running a different operating system. In the event they do not work, you can compile them yourself using a virtual machine with the same OS specifications as your web host uses.

  • Unpack your freshly downloaded binaries using the following command:
    tar -xvjf git-1.7.3.4_centos5.2.tar.bz2
  • Now use your favourite text editor and add the following lines to the bottom of this file: ~/.bashrc
    export GIT_BIN=${HOME}/git
    export PATH=${GIT_BIN}/bin:${PATH}
    export LD_LIBRARY_PATH=${GIT_BIN}/lib:${LD_LIBRARY_PATH}
    export GIT_EXEC_PATH=${GIT_BIN}/libexec/git-core

    Note: if the file ~/.bashrc does not exist, create it and copy those lines to it. After adding those lines, you’ll have to modify ~/.ssh/authorized_keys file, Here’s a sample of my ~/.ssh/authorized_keys file:

    ssh-rsa AAAAB3NzaC1yc2
    hW9fKuSqmv2cxuL8v4HauJ42B6mdqqytwonmABb8CxjTErLZ9jOLbnGHgSUpOmUc+xZicyqc/1bEz0+q
    f+XdwxwT8zHhMj/jkjjjnklkiiiupmb33NrrHtDGh21y7SrcX1wHojUcOYRVa22PrB
    pIDuX9+YXD1iM5JGhW5mSWY3CnsIJ6QFAX3mSXOBh/QRDWuh66VCj809vNcHQ6CwvWwdigm9Bwe3TzDK
    hW9fKuSqmv2cxuL8v4HauJ42B6mdqqytwonmABb8CxjTErLZ9jOLbnGHgSUpOmUc+xZicyqc/1bEz0+q
    7z3/hfNJLjgEO6yKIkY8Y29gj86KjfZVU2tQ== Chuka@CHUKA-PC

    Next add the following code to the beginning of the file:

    command="if [[ \"x${SSH_ORIGINAL_COMMAND}x\" == \"xx\" ]]; then /bin/bash; else source ~/.bashrc; eval \"${SSH_ORIGINAL_COMMAND}\"; fi; "

    This tells your ssh session where it can find your git binaries every time you login remotely via ssh and try to run a command.

  • The next step is to initialize a bare repository on your GoDaddy servers to which you will be publishing from your local server. Create a folder in your hosting account home folder named “repo”, change directories to it and run the following commands:
    mkdir ~/repo
    git init –bare –template ~/git/share/git-core/templates ~/repo/app_name.git
    cd ~/repo/app_name.git
    git update-server-info

    After creating your online repository, you may logout from your GoDaddy server.

Setup & Publish your local repository

Here, you’ll be initializing and setting up a new local Git repository (You can use your development IDE, NetBeans in my case to do this if it has a Git plugin) and tell your local repository where to publish your file to on GoDaddy’s server. For the purposes of this tutorial I will be using “app_name” as project name.

  1. Change directories to your local application folder and run the following commands, don’t forget to substitute your local application path.
    cd /c/xammp/htdocs/app_name/
    git init
  2. Next step is to add all files in your app to your local repository. But before that, Git records your name and email address with every commit you make, so you’ll need to tell Git what these are. Run following commands:
    git config –global user.name ‘Your Name’
    git config –global user.email ‘you@somedomain.com’
  3. Next, we add all files to the repository and then we commit everything
    git add .
    git commit -m “Initial Commit” .
  4. Next we’ll tell our local server where to find our GoDaddy online repository which we setup in the previous section of this tutorial:
    git remote add origin ssh://username@domain.com/~/repo/app_name.git

    Note that we used a “/” after the domain syntax instead of “:” as we would normally would for ssh.

  5. We are now ready to do our initial push to GoDaddy servers online:
    git push origin master

    If all goes well, you should be able to push your local repository to GoDaddy successfully.

  6. Now that we are able to push files online, there’s just one last bit we need to tidy up; ssh into your GoDaddy account and run the following command:
    git clone –template ~/git/share/git-core/templates ~/repo/app_name.git ~/html/app_name
    cd ~/html/app_name
    git pull

    This makes a clone of your repository and deploys files to your web-server [could also be your live-site]. The next command “git pull”, retrieves all files which has been pushed to your online repository from your local machine and makes sure its up to date.

    If you want to update your live-site automatically any time you do a “git push”, you’ll have to make use of the “post-receive” hook file. Use your favourite text editor and create the file ~/repo/app_name.git/hooks/post-receive and copy the following lines to it:

    WORKDIR="/FULL/PATH/TO/html/app_name"
    export GIT_DIR="$WORKDIR/.git"
    echo "Starting Pull"
    cd "/FULL/PATH/TO/html/app_name"
    git pull
    echo "Pull finished Successfully"

    Note: you can get your full path by running “pwd”. Now hopefully if you followed these steps correctly, you should now be able to do a git push and update your GoDaddy repository and effect changes to your live-site at once.

I hope you found this tutorial quite helpful.
PS: I picked Sola’s brain a lot while writing this :)

32 thoughts on “Installing Git on Godaddy

  1. Very nice article, helped me a lot..
    however, there are a few mistakes here,
    1)- ‘ssh’ is wrongly spelled as ‘shh’ at some places.
    2)- command=”if [[ \"x${SSH_ORIGINAL_COMMAND}x\" == \"xx\" ]]; then /bin/bash; else source ~/.bashrc; eval \”${SSH_ORIGINAL_COMMAND}\”; fi; ”
    was not working for me when i copied it directly, when i copied this code from another webpage, it worked.
    Hope this helps!

    • Hello Arun, thanks for the pointers, i have updated the ‘shh’ issue, but for the 2nd one, i doubled checked that line of code, and it seems ok. Maybe when you copied: ” was replaced with “ anyways thanks a lot!

  2. Thank you for this article–I found it very helpful! I had to do a few things differently:

    1) instead of -bash, -template; –bash, –template, etc.

    2) git remote -set-url origin ssh://path/to/.git produced “no such remote ‘origin’” error; instead used git remote add origin ssh://path/to/.git

    3) git couldn’t find git-receive-pack on the server. Apparently, connecting via ssh wasn’t loading paths in either .bash_profile or .bashrc. I used –receive-pack full/path/to/git-receive-pack and that worked. Afterwards, I added the following to git config:
    git config remote.origin.uploadpack /full/path/to/git-upload-pack
    git config remote.origin.receivepack /full/path/to/git-receive-pack
    and now git push origin master works fine.

    4) while pushing, got this error:
    error: pack-objects died of signal 13
    I had to break up my project into smaller chunks and that resolved it.

    I wasn’t able to get the post-receive hook to work. I googled the problem and tried a few different solutions, including adding shebangs and “env -i git pull” to the post-receive file, but nothing seemed to work. If you have any ideas about what the problem might be, I’d love to hear them. Anyway, thanks again!

  3. Thanks a lot for writing this up…
    I’d like to add the problem i faced:
    1. Firstly dunno why but the curly braces in export statements didn’t work, so i removed them
    2. space should be considered when setting up ~/.bashrc file
    3. export -p command also helps..:)
    4. In your ssh file, make sure everything goes in one line…

    • thanks for this list, point #4 was tripping me up.

      The OP just says “beginning of the file”, which is slightly misleading. It should specify that that the command is prepended to the beginning of the line, without a carriage return, so the whole thing should look like this:

      command=”if [[ \"x${SSH_ORIGINAL_COMMAND}x\" == \"xx\" ]]; then /bin/bash; else source ~/.bashrc; eval \”${SSH_ORIGINAL_COMMAND}\”; fi; ” ssh-rsa AAAAB3NzaC1yc2ECCCCDAQABAAABAQDSNqqbOACGl2qyQBkPFfSL2eNxtP0W61TKIL19VQAdRcdCBF/ZJSyFYAGRmq6rgr3yVmD4f+sfP1DM4puMaldaV7nf8gx9spqyLc4CG36DIjcS5tGvNQyUqEZVvhpsRlxsJcyzyNfHZVXD78WfjLZuiggRQfqKlB1wRdzE95GZcrt3nrSgh4dx2lTwzihniuEmtZUJDLk8LTqNXE+zn+dilSRwCJwjr+2FNoOggrT+bcNm07U2l3mYTf2qFifq1CzzoYqgH5jRhpXV2Z1qkQZ28CPU14G+l7c1PBjk5efxfHhSex2bSrxFa9XUtnJyweyoho2IoYTBe+2On165CWml username@machine

  4. Hopefully this helps anyone who is having issues… took me hours to resolve!

    If you do not have ~/.bash_profile, you need to create one and use the following code to refer to the ~/.bashrc file.

    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

  5. Hello !!

    Thank you so much for a wonderful post. Do you know how to setup keyless ssh on go daddy shared hosting account ? I was able to install and configure git but even though I created and published id_rsa.pub on .ssh/authorized_keys file @the server go daddy is still asking for password for login. !!!

  6. What does this mean:

    ” After adding those lines, you’ll have to modify ~/.ssh/authorized_keys file, Here’s a sample of my ~/.ssh/authorized_keys file:”

    There is no explanation on how to modify the file or why this is necessary, please explain?

    • You can use nano or vim to modify the file and paste your public ssh key. this is required to use public key authentication so it wont ask for a password everytime.

  7. Pingback: Learning about Git Hub | Stephen Chapman

  8. Pingback: Version Control: Setting Up Git on Godaddy | Sam Tobia

  9. This article was just what I needed
    There is one thing that confused me for a good 15 minutes considering my favorite text editor was notepad++, then my next favorite is notepad. So I figured this would be done locally.

    But for the ~/.bashrc you’ll want to use vi most likely since it doesn’t use an install
    http://www.cs.rit.edu/~cslab/vi.html for the commands

  10. I have followed all the steps but I am getting this error
    git: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

    Couldn’t find any solution online , I appreciate your help to fix it

    Thanks
    Rania

      • I followed these steps last night and was able to create a repo with no problem but this morning I get the same libz.so.1 not found error

        • I run into the same issue recently. As it turns out, godaddy host deluxe has git pre-installed (Don’t know about other hosting variants), so you no longer need to install git or modify .bashhrc. Authorize public ssh key from Cpanel and then add that line mentioned, at the beggining of the file, leaving a space between the function and key. Then you can connect with putty(having imported the private key) and run the git commands. You can get git path by running git –exec-path.

  11. I have followed all the steps but I am getting this error
    git: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory, I appreciate your help to fix it

    Thanks
    Rania

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">