Woody Hayday
+44 (0) 7855 814 203
wh@near2.org
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.
- Games
- Ideas
- Looking Back
- Looking Forward
- Music
- Open Letters
- Photography
- WoodyLabs
- Writing
- Affiliate Marketing
- Business Intelligence
- Projects
- Search Engine Optimisation
- Social Media
- Software
- ASP.Net
- Browser Compatibility
- C#
- CSS
- Facebook Graph API
- Javascript
- PHP
- Snippets
- Transactional SQL
- Web Development
- Wordpress
- SQL Server
- SSRS
- Visualisation
- Web Technology
- Wiki Media
18 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