Skip to content

Push Git Repo Into Shared Hosting Account Like Hostgator

by arlo on January 28th, 2012 

Many use 3rd party git hosting ( to host their git repos, but sometimes you’re not wanting to take your project to a social network. Sometimes your repo is for yourself, for your website and no one else. I want to run you through how to setup your Hostgator account with the configuration needed to push directly into Hostgator in 3 steps. Theoretically you can do this with any shared hosting that gives you SSH access and has Git Client installed.

1.) Setup Hostgator

Make sure you have SSH access. Shared hosting accounts with Hostgator do not come with SSH access by default. You will have to go to the support chat and ask for SSH access or go here and ONLY follow instructions for “Shared Web Hosting”, this will only take minutes and is effective immediately.  Once they give you access, make sure you can login. SSH port for hostgator is 2222. Here is how you would SSH into your account with your Hostgator username and password.

ssh -p 2222
Enter your password: *********

Get your public key into Hostgator.Your public key is located at ~/.ssh/ (on your workstation), copy the contents and paste it in a file on Hostgator: ~/.ssh/authorized_keys.

Incase you don’t have ~/.ssh/ on your workstation, run ssh-keygen in your console and hit enter all the way through. At the end of that, you will have the ~/.ssh/ file on your computer.

If ~/.ssh/authorized_keys does not exist on Hostgator, then create it with touch ~/.ssh/authorized_keys.

Configure your repo on hostgator. First, you need to set a config option in your hostgator repo to accept pushes into this working directory. SSH into hostgator, navigate to your repo directory and run this command:

git config receive.denyCurrentBranch ignore

Finally, you need to set a git hook that will refresh your working directory after the push has been accepted. Save the following content in: PATH_TO_REPO/.git/hooks/post-receive.

# Save this in: PATH_TO_REPO/.git/hooks/post-receive
GIT_WORK_TREE=../ git checkout -f

Then, make it executable with chmod +x PATH_TO_REPO/.git/hooks/post-receive

2.) Setup Your SSH Config Locally

Automate SSH connection for Hostgator. In order to add hostgator as a git remote, you need to automate the fact that you will be connecting to hostgator via port 2222 and you will not be using your password for authentication. Your need to edit/create the file ~/.ssh/config on your computer. Then add this content.

  Port 2222
  PreferredAuthentications publickey

Now, you should be able to login with ssh without needing to type your password. If this is not the case, start over at step 1.

3.) Setup Hostgator as a Remote

Add your domain as a remote. On your computer, navigate to your git repo and run this command:

git remote add hostgator-live

Now, you can make you changes to your repo and when you are ready to push your changes:

git push hostgator-live

Something to think about

With this setup it is now easy to have a “dev” site on your hostgator account too. SSH into hostgator and replicate your repo into a different folder (~/www/dev). Locally, setup a new remote:

git remote add hostgator-dev

So, from now on you can git push hostgator-dev to test out your new changes. When you are ready to make your changes live: git push hostgator-live

From → git, Workflow

  • Arlo Carreon

    Glad it was helpful!

  • ETheRed

    Thanks for the quick reply Arlo, there is something else I will like to confirm with you that I spent quite some time trying to figure what to do.

    On the step called “Configure your repo on hostgator” where I am suppose to copy the mentioned content into the “post_receive” file, well that file did not exist for me in the “hooks” directory. I end up creating the file, was that ok? or was that file suppose to be there already?

    The only files in the “hooks” directory where the following:
    - applypatch-msg.sample
    - commit-msg.sample
    - post-update.sample
    - pre-applypatch.sample
    - pre-commit.sample
    - prepare-commit-msg.sample
    - pre-rebase.sample
    - update.sample

    Thank you

  • Arlo Carreon

    You should be ok creating it yourself. Make sure you give it executable privileges. “chmod +x path/to/post-receive”

    As a side note, this post is 2 years old I haven’t looked at possible changes to these git hooks. If post-receive doesn’t work I would suggest using post-update.

  • lettuce

    Hi I am new to publishing a website, it seems like I followed all the steps and it pushes successfully to hostgator repo, but how do i view the website? I used handlebars instead of .html

  • Otto Salin

    I should try that out asap. Thanks! ;)

  • Agus dk

    I have little problem. I want to my friend can pull or clone my repo HG but i want my friend have personal username not my existing username. HG can support to add new username ? Please help me.

  • Arlo Carreon

    For this setup the “username” is based on SSH credentials. I understand you don’t want your friend to have the same SSH credentials as your account. I would suggest not to follow this guide and to use a web hook.

  • Agus DK

    thanks for reply and your suggestion, in the future i dont want use github again, because i want use this private. you have other suggestion for this case?

  • Arlo Carreon

    You can still use the webhook with bitbucket. Bitbucket has free unlimited private repos.

  • Arlo Carreon

    The webhook I mentioned above also works with BitBucket which has unlimited free private repos.

  • jacobirr

    Thanks for such a great article. I’ve got all this setup and in place, and I can even see my commits working in the log file on hostgator… The only issue I’m having is that my files are not updating. I use git add index.html then git commit -m “testing index change” and then I do git push hostgator-live …so I get the log entry, but the index.html file is still the old version… any ideas why?

  • jacobirr

    I also just found this error when trying to push:

    remote: fatal: cannot exec ‘hooks/post-receive’: Permission denied

  • Arlo Carreon

    Yup. That post-receive hook is the one responsible for updating the files after a push. It seems that the permissions on ‘hooks/post-receive’ are not set so that it is an executable file.

    chmod +x /path/to/hooks/post-receive

    If that fails try:
    chmod 777 /path/to/hooks/post-receive

  • pstrawberrie

    Thank. You. So. Much!!!!!!!!
    Saved me so much time I feel like a pro after reading this! ^_~

  • Dan

    I’m having an issue with the post-receive step. I keep getting an error:

    remote: error: cannot run hooks/post-receive: No such file or directory

    My repo is in the public_html folder and the file is placed in the hooks directory with the correct contents, and I even included the absolute path in my post-receive file:

    GIT_WORK_TREE=/home3/user/public_html/ git checkout -f

    No matter what I do, I keep getting the same error. I’ve tried changing the location of the hooks folder to see if it will execute, but I think it might be something to do with the location of the bash or sh file? I really don’t know what to do. The git log is being updated, but none of the files are being transferred due to this error. Please let me know your thoughts.

  • Arlo Carreon

    It might be that “bin/sh” does not exist. I know Hostgator has been making alot of changes lately so you might need to use “bin/bash” instead. Let me know if that works.

  • Dan

    Thanks for the fast response. Unfortunately, I’ve tried this and had no luck. I’ve had to set up my workflow the old fashioned way, where I push to github and then use a webhook to automatically pull to the server. This works in nearly the same way, but I’d really like to have the flexibility to get this to work independent of github.

    I don’t know if you have any other thoughts. I’ve looked around and most people that have this same problem are on rails and their answers don’t apply.

    It does seem to be an issue with the execution of the file, not the actual post-receive file location. So your recommendation was a good one. I just don’t know how to troubleshoot any further.

  • Arlo Carreon

    * Make sure the file is executable: chmod +x path_to_file
    * Run the hook via command line to see if it runs correctly
    * If it does run, might be a permissions issue
    * is git available when you ssh into HG?

  • Vishal

    Thanks Arlo.

    I am not able to pass through second stage. I have reseller account with hostgator. I am facing following error. Not sure how to fix this.

    Error : Permission denied (publickey,password,keyboard-interactive).

    Attaching screenshot of debug message from my workstation.

  • Arlo Carreon

    Step #1 “Get your public key into Hostgator”. You didn’t setup your public key on your dedicated server properly. If you continue to have a lot of trouble feel free to reach out to me on I will help you fix it in minutes. Link is on the top of the right sidebar.

  • Vishal

    Sure Arlo, thanks for tip. will get in touch with you if I need further help.

  • Arlo Carreon

    Sorry for the delay. This comment slipped through the cracks. Maybe your post-receive file is not executeable.

    Try: chmod +x /path/to/post-recieve

    If it is still not working I can try to debug for a few minutes. Let me know if this helped out.

  • Tuan Duong

    Awesome article, thank you so much. Shame that windows shared hosting doesn’t support SSH.

  • Arlo Carreon

    you are welcome! I am glad the post helped in some sort of way.

  • James

    Hi, thanks for making this. Im having a hard time with it though, cant seem to get past step 2. I get the following:

    Permission denied (publickey,password,keyboard-interactive).

    when I attempt to ssh in after creating my config file. I’m pretty sure I’m following the instructions correctly, but there were some things that I was unclear on so perhaps I am wrong. Any help would be greatly appreciated!

  • Arlo Carreon

    It seems you did not setup step #1 correctly. You need to copy the public key from your workstation and paste it into a special file on HG. FYI, it is the same public key used for integration of Github or bitbucket. if you can already push to github, you can probably copy it from Github and paste it into your HG server.

  • Wahsidin Tjandra

    hii Arlo,

    how are you day ? should be great right


    your tuts is awesome, but i have problem,

    Where is the File ?
    i can not find the file that had been uploaded into the server.

    The process

    i had pushed using

    $ git remote add origin

    $ git push -u origin master

    “everything up-to-date”

    but i can not find the file that had been uploaded on, public_html/lab

    Where the files actually ?



  • Arlo Carreon

    Your files’ content is being held (tracked) by the git repository. If your files don’t show that is because the working directory is not updated. I’m pretty sure you are experiencing this issue because the hook is not working. The git hook is supposed to run 1 command ( git checkout -f ) after it receives a push, this command is what syncs your working directory with the latest git commit.

    I would investigate why the hook is not working or being executed.

  • Chris Martin

    Great tutorial. After a few hours I finally got it working. I wanted to leave this comment to save others some headaches. For some odd reason on my local machine’s config file I had to change this line in step 2:

    PreferredAuthentications publickey


    The equals sign finally got my problem solved. The error being generated was something along the lines of Permission Denied (publickey,password,keyboard-interactive).

    An additional helpful command was ssh -v (making it verbose gave additional information)

    I am running MacOSX 10.9.5 on my local and I was connecting to Hostgator. OpenSSH 5.3p1, OpenSSL 1.0.1e-fips

    Hope this helps someone.

  • FroyT


    First of all thank you for posting this tutorial!

    I am a little confused as to what the “site-directory” in this line:

    git remote add hostgator-live

    is about. After running it a second time I get a message saying that:

    “fatal: remote hostgator-live already exists.”

    I proceeded to the next step and I am getting this error when running the git push hostgator-live:

    fatal: I don’t handle protocol ‘’

    Thanks again for the help any assistance would be appreciated!

  • Turner Kilgore

    What a fantastic tutorial! Thank you! I also found this tutorial,
    that allowed me to take it a step further. I set up my local “~/.ssh/config” file like so:

    Host hostgator
    HostName [my.ip.add.ress]
    Port 2222
    User [username]
    PreferredAuthentications publickey

    This has two benefits. I can now connect easily with:

    $ ssh hostgator

    and when adding the remote I simply used:

    $ git remote add staging hostgator:public_html/[my-site-root]/

    Thanks again for this great tutorial!

  • Rafael Cavic

    I tried to push, and terminal replied:

    iMac-de-Rafael:rei cavic$ git push hostgator-live
    ssh: connect to host port 22: Operation timed out
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.


    What can i do?

  • Arlo Carreon

    You might not have SSH access setup on your HG account. Can you SSH into your HG account without using git?

  • Rafael Cavic


    iMac-de-Rafael:~ cavic$ ssh -p 2222
    Last login: Fri May 6 20:42:33 2016 from [~]#

    I be able to login without needing to type my password too.

  • Arlo Carreon

    awesome! So ssh and git push have to use the same ssh configuration. In your SSH command you use port 2222, but in your original error message from git is says it can’t connect on port 22.

    This leads me to believe you didn’t setup your SSH configuration correctly and git is not picking it your SSH settings.

    Make sure you did step #2 correctly.

  • Rafael Cavic

    Sorry, my fault.
    Thank you for your help!

  • Ronald Araújo

    Thank you very much. :)

  • Shimona @ Sidecar Photo

    Fantastic tutorial, I was able to get this working on inmotion based on your directions. Some edits of course, but it’s working! Thanks.

  • Carlos Montoya

    Hello I think I made a mistake when I ran ssh-keygen i added a passphrase, now when i try to ssh to hostgator it asks me for that passphrase, is that a problem? i kept going with the tutorial after that and i set the repository as remote but now when i try to pull with:

    git pull hostgator-live

    i get:
    ssh: Could not resolve hostname says my domain): Name or service not known
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

    Help please, where did it go wrong?

  • Arlo Carreon

    You definitely don’t want to use a passphrase when you generate your public key. It gets real annoying real fast. I would redo your public key and add it to your hostgator home directory (part 1 of step 1).

    The could not resolve hostname error is weird, I wouldn’t expect that from having a passphrase on your public key. I would have expected “public key failure” type of error. Make sure your domain is spelled correctly. Keep me updated.

  • Carlos Montoya

    Yes i was misspelling the domain name sorry, so i removed the remotes with

    git remote rm hostgator live

    and made new ones: hostgator-dev and hostgator-beta, and then i tried a push to dev and i got

    $ git push hostgator-dev
    fatal: The current branch master has no upstream branch.
    To push the current branch and set the remote as upstream, use

    git push –set-upstream hostgator-dev master

  • Arlo Carreon

    So a couple issues here:
    1) your ssh connection still wants to use a passphrase. This is an SSH setup issue no relevant to git setup.
    2) It seems you probably created an empty directory on Host Gator, did “git init” and now are try to push your local git repo to this new directory? I say that because git is scared about the discrepancy between the current [HG] directory and the contents you want to push.

    To resolve #2, it might help if you already had this repo in Github or similar. Make sure your local repo and Github are synced. Then in HG do a git clone into the location you want to start pushing. This will make HG and your local repo in sync (as far as commit history). From there you should be able to make changes locally and push to HG without issues.

  • Carlos Montoya

    Here are my responses:
    1) Can i finish the setup and make the changes to my ssh key after?
    2) Yes thats how i did it i created a folder then i ran git init on hostgator and also did the same on my pc, how can i solve it without github since i dont have it on github I’m just triying to start a new project, I thought should i create a new folder and run git init on host gator and then clone that into my pc? is this correct? or what would you suggest?

    And since i haven’t said it before thank you very much for your assistance on this.

  • Arlo Carreon

    1) Yes. This is just an SSH connection with HG. You can change this at anytime.
    2) If you are setting up new projects, I would do what you mentioned. Create the folder on HG, create a simple file and make a commit. This will force the master branch to get setup. Then do a git clone onto your local machine. Then you will have both repos “synced” as far as commit history is concerned.

  • Carlos Montoya

    It worked fine that way, thank you very much, so if i want to include other pcs in this project i just need to paste their ssh key in the authorized keys folder?

  • Arlo Carreon

    That is correct, it’s a file but yes. Add their public keys to the same file you put yours in.

  • Carlos Montoya

    I already setup another 2 pcs to collaborate on my project and everything went smoothly thank you very much, what i am having problems with is removing the password from my ssh key, but i wont nag you with that.

  • Jacob Hershberger


    I keep repeating the steps as directed, but when I get to step 2, I get the following error Connection timed out

  • Arlo Carreon

    That means you are connecting to your hosting server on the wrong port. Do you use HostGator or are you with a different shared hosting company? You should find out which port they use for SSH connections. If it is HG, then you need to connect on port 2222. You also need to activate SSH on your shared hosting account, which is outlined at the beginning of step 1.

  • Jacob Hershberger

    I’m using HG, using port 2222, I’ll have to re-look at step 1 again. Thanks for your response! I’m able to log into my HG account via commandline just the login without password fails