Find it
Woody Hayday

Fresh Ideas

Hi there! This is my old blog, I don't hang around here much.
You can now find me trying to mix things up here:
Visit WoodyHayday.com Subscribe To My Email List

1and1 Web Hosting & Git – Installing it for singular dev

I have a new project in the works and I thought it about time to get a verioning setup working beyond locally, I don’t want to use a PaaS (like Cloud control) though for this one as its Top Secret (for now.) Yeah Yeah I know, shared web hosting, 1and1 – not so secret eh? Well behind a .htaccess passworded directory is better than sitting on AWS via a PaaS, it is, believe me.

The benefit of using GIT in the way below is that it maintains version history AS WELL as offering a managed host, i.e. it deals with uploading as well as versioning (in 1 git bash push.)

So here’s the scenario – there’s one of you, or maybe a few core founders/dev’s and you want to use GIT to version control your developments of a new web app or site. You already have a shared hosting account with 1and1 which works fine up to 20k hits a day or so, is there really need to have the thing scalable on demand from day one? No? Great, read on. If you REQUIRE scalability off the bat (I bet you don’t, really) then go find a PaaS/jump on AWS, for now here’s how to get GIT versioning (with automatic publication) working on your 1and1 shared hosting.

Firstly go read this, its a great guide that pretty much* got me there (95% of the credit to Abhijit), there’s just a few changes to get it to work on 1and1.

How I did it: GIT on 1and1

Load up your FTP, get to the root of your hosting and make your main site dir, in this case we will call it AppDev1:
/AppDev1
Next make two directories underneath it: “repo” and “live”, I shall explain these after you have made them:
/AppDev1/live
/AppDev1/repo

What these two are going to do is give you a live “root” for your web app/site as well as a GIT repository (which stores all the changes.) By separating them you keep everything simple. [live = web root folder, repo (or whatever you call it) = git bare repository.]

Next locally (on your machine) create a folder which you want to develop in:
C:/EpicNewApp

…And load up GIT BASH (assume you have) and enter the following:
cd "C:/EpicNewApp";
git init;

Next go ahead and load your SSH client (putty) and log into your 1and1 Account (there is guidance on 1and1 under SSH accounts, if you need it.) Once logged in enter the following:

cd "/AppDev1/repo"
git init --bare
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE="../live" git checkout -f
chmod +x hooks/post-receive

*note: This differs from the aforementioned guide in the address entered under GIT_WORK_TREE, this is the only way I could get this setup to work on 1and1.

You can also simply stick these lines into a file called post-receive and upload the file to the “hooks” folder of your new bare repository (repo), if you are so inclined.

That’s it, your done with the SSH, now you can bind a remote location in GIT BASH (replace the obvious:)
$ git remote add web "ssh://u99999999@yourMain1and1Domain.com/~/AppDev1/repo/"
…And go ahead and push to 1and1 (you will need your SSH password to do so.)
$ git push web +master:refs/heads/master
All being well this should have pushed a version to your /AppDev1/repo folder and also updated the live files as per your changes!

Happy Ghetto Versioning!

Note: As per comments, removed .git reference from link, thanks Ano.

This entry was posted in Code, Projects, Snippets, Web Development, Web Technology and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

35 Comments

  1. Ano
    Posted January 22, 2012 at 8:25 pm

    for some reason it doesnt work , it keeps on saying

    blah/nlah.git does not appear to be a git repository
    the remote end hung up unexpectedly

  2. Posted January 22, 2012 at 8:40 pm

    Hmmm I did get that too, had to keep at it though, are you using the right endpoint? Did you copy it from above?

  3. Ano
    Posted January 22, 2012 at 9:38 pm

    yes i am using the right end point

    btw , i have been going through soo many websites , and guess what i even called 1and1 and almost got into a fight with one of there customer support cause he couldnt even understand what i was saying which got me mad

    i think the problem has to do with the public and private keys which are necessarily to do the connection

    the link you provided in your post , assumes that you have your public key saved ~/.ssh/somepublickey

  4. Ano
    Posted January 22, 2012 at 9:42 pm

    i am afraid that i have to always upload my code and then do the commit on the server. that would suck really bad

  5. Posted January 23, 2012 at 9:09 am

    Hmm. I don’t think it’s a private key issue, perhaps our shared hosting resides on different servers or similar, I bet your problem is to do with this dude:

    $ git remote add web “ssh://u99999999@yourMain1and1Domain.com/~/AppDev1/repo/.git”

    I had to change it from the linked article in this to get mine to work, look at the ending bit from /AppDev1 (a folder in the root of your hosting) – where does the git repository actually exist in hard files?

  6. Posted January 23, 2012 at 9:09 am

    Plus, that’s just how we all used to do it! ha.

  7. Ano
    Posted January 23, 2012 at 3:15 pm

    hmmm

    isnt the actual repository exists in the place where you initialize your repository?

    so if i am in the root and i do
    $ git init

    my repository will be @ “ssh://u99999999@yourMain1and1Domain.com/.git

    i also noticed that if i am in a folder called myApp.git then
    git init , doesnt create “.git” folder inside myApp.git. it actually makes myApp.git my repository

    so i am a bit confused about this
    i am going to play a bit with the link but i’ll let you know how it goes since you suspect that the issue has to do with the link

    thanks dude

  8. Posted January 23, 2012 at 5:26 pm

    It has to be a bare repository, that’s part of it – so it needs to be a folder like “repo.git” (or at least have the git repo in it. Also it seemed to need the ~/ in it before the root for me (I didn’t bother checking why but it needed it.)

    Yeah sounds to me like its the link.

    No worries, Good luck :D

  9. Ano
    Posted January 25, 2012 at 3:11 am

    this is crazy ,

    when i did the following
    —————————————–
    [MY COMPUTER] (master)
    $ git remote add web “ssh://[MY ID]@[MY WEBSITE]/~/AppDev1/repo”

    [MY COMPUTER] (master)
    $ git clone web +master:refs/heads/master
    fatal: repository ‘web’ does not exist <<<<<< this is the error i get

    then i did the following of course after removing the old web
    —————————————————————————————–
    $ git remote add web "ssh://[MY ID]@[MY WEBSITE]/~/AppDev1/repo/.git"

    [MY COMPUTER] (master)
    $ git push web +master:refs/heads/master
    [MY ID]@[MY WEBSITE]'s password: [SOME PASSWORD]
    fatal: '~/AppDev1/repo/.git' does not appear to be a git repository
    fatal: The remote end hung up unexpectedly

    this is really wierd :S

  10. Ano
    Posted January 25, 2012 at 3:17 am

    ok i removed the old web again and added the following

    $ git remote add web “ssh://[MY ID]@[MY WEBSITE]/~/AppDev1/repo” <<[this is the first one i tried in my older post]

    then as you may have noticed in my older post , i did
    $ git clone web +master:refs/heads/master

    so now i did push instead
    $ git push web +master:refs/heads/master

    here is the error i receive
    error: src refspec master does not match any.
    error: failed to push some refs to 'ssh://[MY ID]@[MY WEBSITE]/~/AppDev1/repo'

    which is a different error message

  11. Ano
    Posted January 25, 2012 at 3:38 am

    done its perfectly working :)

    so here is a summary of what has happened

    i think i just missed the ‘~’ in my link to my website , and that’s about it

    the last error i got was solved by just adding a file to be committed , it is just complaining about having nothing to push to the server lol

    now there is a lil error from your side , you should remove the .git from the link you have in your description , you dont need that

    i hope this will make this post complete hehe

    thanks alot for all the help man

  12. Posted January 25, 2012 at 9:07 am

    Ano, No worries! Great to hear you got it working…cool when it does eh? I will adjust post now. Happy Developing :)

  13. Ano
    Posted January 25, 2012 at 4:48 pm

    lmao yah it is really cool when it does
    lol happy developing to you too , this sounds like a xmas greeting ;)
    cheers

  14. Posted January 25, 2012 at 6:15 pm

    lol yeah it’s my new one. ha.

  15. Ano
    Posted February 6, 2012 at 3:17 pm

    Hey Woody
    its me Again lol

    umm do you have any links on how to integrate trac as well with my shared 1and 1 hosting

    let me know if you have any :)

  16. Posted February 6, 2012 at 3:33 pm

    Hey Ano,

    No, never used it – although if you find a good link then please do share :D

  17. Ano
    Posted February 6, 2012 at 11:00 pm

    Alrighty, i’ll let u know about it as soon as i do

    i saw few but they are hard to do and lengthy ,

    i might have to go through the links which needs alot of work to be done , because i couldnt find anything simpler

    oh well

    i’ll let u know :)

    Thanks Woody

  18. Posted February 7, 2012 at 9:01 am

    Might be worth just getting a virtual server/another host if its tons of work, sure its doable though.

    Cheers Ano

  19. Joseph
    Posted May 1, 2012 at 11:15 pm

    Would it be possible to use separate branches in this configuration?

  20. Posted May 2, 2012 at 9:53 am

    Hi Joseph,

    I *guess* it would be possible by adapting the post-receive hooks – there might be simpler solutions though. If you find a solution (and it is possible) then please do stop by again and drop it in these comments, that’d be really useful for future projects!

  21. John
    Posted July 31, 2012 at 6:24 am

    I am new to git.
    Nice article, got the commit section working though not sure how to use this to clone the repo to a new user.

    I.e. git clone does not seem to work.

  22. Posted July 31, 2012 at 8:26 am

    Hi John,

    To be honest I’ve only ever used this for single dev work, if you get it to work otherwise, please do let me know though!

  23. David Tucker
    Posted March 18, 2013 at 11:42 am

    Hi – I have a 1and1 shared business account and kept getting a “‘fatal: Could not read
    from remote repository. Please make sure you have the correct access rights and the repository exists’ error when I tried to use the push comand.

    I contacted 1and1 and got this reply “The ‘push’ command is actually a command to access the server remotely. However, in shared hosting packages, remote access of the server is not possible for some technical reason. This command will work if you have your own server like having a dedicated server package. ”

    I couldn’t be bothered to argue with them so I found BitBucket which does the job without the hassle.

  24. Posted March 22, 2013 at 2:45 pm

    Hi David,

    It’s whatever works for you I guess. This does definitely work for 1and1 though as I continued to use it for a while after this post.

  25. Ano
    Posted April 29, 2013 at 4:12 pm

    Here i am again exactly a year and 2 months after my last post
    i confirm that this still works and i still use it.

    Just sayin hi Woody :)

  26. Eliliado
    Posted September 13, 2013 at 11:53 am

    Hi Woody.
    First of all, thanks for your work.
    I have a simple question about the remote server:

    cd “/ AppDev1/repo”
    git init – bare

    Is Git installed in (remote)1and1server?

    Sorry for my English.

  27. Posted October 11, 2013 at 12:33 pm

    Git should be on your local machine Eli!

    Thanks Ano :)

  28. Eden Chen
    Posted December 7, 2013 at 5:08 am

    thanks so much for the direction, very helpful. I’m able to push the code to repo but nothing went into live, any ideas? if i go into the hooks folder and “vim post-receive” I get this:
    #!/bin/sh
    GIT_WORK_TREE=”../live” git checkout -f
    chmod +x hooks/post-receive

    anything else I could be missing?

  29. Posted January 3, 2014 at 5:22 pm

    Hmmm, not sure – you’ll have to dig around online – sorry Eden!

    W

  30. Dylan
    Posted January 5, 2014 at 4:27 am

    when i type git init –bare i get “Invalid command”. is git automatically installed on 1and1 servers? or am i missing something?

  31. Posted January 6, 2014 at 5:26 pm

    Didn’t encounter that problem, sorry Dylan. Maybe ask 1and1 directly?

  32. Jesse
    Posted January 9, 2014 at 9:53 pm

    @Dylan, it should be installed on the server. Just by looking at your command, it looks like you forgot a second dash before ‘bare’ -> “git init –bare”.

    If you do “which git” and/or “git –version” you should get similar results:

    (uiserver):u99999999:~ > which git
    /usr/bin/git
    (uiserver):u99999999:~ > git –version
    git version 1.7.2.5

  33. Posted January 24, 2014 at 1:55 pm

    ^^ Cheers for helping out Jesse :)

  34. Chris
    Posted August 30, 2014 at 4:33 pm

    I am having the same problem as Ano where i get this error:

    error: src refspec master does not match any.
    error: failed to push some refs to ‘ssh://[MY ID]@[MY WEBSITE]/~/AppDev1/repo’

  35. Posted September 8, 2014 at 2:24 pm

    Sorry Chris, not sure about that one. Please do post back here if you find a solution, this page gets a fair few people looking to get this working and I’m sure they’d appreciate it!

    Cheers

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Like Festivals?

Got a Project?
A Quote..
"The way I am and the way I write are a unity. All my ideas and all my endeavours are myself. Thus, the autobiography is merely the dot on the i."
C.G.Jung
© Woody Hayday 2014