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.
39 Comments
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
Hmmm I did get that too, had to keep at it though, are you using the right endpoint? Did you copy it from above?
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
i am afraid that i have to always upload my code and then do the commit on the server. that would suck really bad
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?
Plus, that’s just how we all used to do it! ha.
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
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 π
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
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
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
Ano, No worries! Great to hear you got it working…cool when it does eh? I will adjust post now. Happy Developing π
lmao yah it is really cool when it does
lol happy developing to you too , this sounds like a xmas greeting π
cheers
lol yeah it’s my new one. ha.
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 π
Hey Ano,
No, never used it – although if you find a good link then please do share π
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
Might be worth just getting a virtual server/another host if its tons of work, sure its doable though.
Cheers Ano
Would it be possible to use separate branches in this configuration?
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!
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.
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!
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.
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.
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 π
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.
Git should be on your local machine Eli!
Thanks Ano π
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?
Hmmm, not sure – you’ll have to dig around online – sorry Eden!
W
when i type git init –bare i get “Invalid command”. is git automatically installed on 1and1 servers? or am i missing something?
Didn’t encounter that problem, sorry Dylan. Maybe ask 1and1 directly?
@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
^^ Cheers for helping out Jesse π
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’
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
Hello @ all,
i have the same issue like Eden Chen (Posted December 7, 2013 at 5:08 am).
When i push to the repo but the live version is still the same like before?
I found some solutions with script files or so on, but iΒ΄m not happy with that.
Had anyone found a solution for that?
Thanks!
Hey Georg,
Sorry, not sure if I can help on this one. Hopefully someone else will jump in!
Cheers
I know this is an older post but super useful. Wondered if you or others who happen upon this page had any experience to help my issue – I can connect easily to my repo on 1and1, it loaded up all the usual Git files etc. But, it won’t push anything from the local folder. Im sure my connection is correct because Terminal seems to say things are pushing, but they aren’t appearing. Any input might help!
Hey Boshy,
You sure you’re using the full:
$ git push web +master:refs/heads/master
These comments will be shutting down next week as I’m moving the blog, but hopefully someone can lend a hand!
Comments Archive
Hi there. This is my old blog and it's archived, so you can no longer post new comments on this post (1and1 Web Hosting & Git – Installing it for singular dev).
Read my new blog about writing software and stories at WoodyHayday.com