I generally found this a bit tricky to get all setup so I thought I’d document it for others who want to do the same. The main issue I’ve found is that Git on a server will naturally want an SSH key and user details for authentication. It seemed insane that it took me so long crawling the internet to find a way to actually set it up so anyone anywhere can clone a git repo from my server.

This is a necessity because of my yocto work, I need a way to share my working setup of the NI Linux RT. Anyway, going back to a previous article about Git I followed the same steps as before:

https://github.com/to-ro/install-Git-on-a-GoDaddy-shared-hosting-server

Minor tweaks were that I actually created a folder called nilrt on the server instead. This is to match the repo I intend to have available. Now the next part which was super annoying to figure out was a “git: fatal: Could not read from remote repository“. They were somewhat right in that thread, using

git remote set-url

For instance. The other thing I did was while SSH’d into the server, I would git clone the repo internally to somewhere else, this allowed me to confirm the URL and that it was an authentication issue. I used the article here to find out how to create a public key and SSH upload that to my server:

https://www.ssh.com/academy/ssh/keygen

Weirdly this worked for one repo but not another, I had to repeat the steps for no reason at all…

So now I could git clone using SSH and push my repo up to my server. Almost there, just how to make it publicly available for cloning? Wrong, just a few notes on some discoveries:

You should initialise your repo with git init –bare, this proved useful:

https://stackoverflow.com/questions/11117823/git-push-error-refusing-to-update-checked-out-branch

One thing that could me out was that the files didn’t appear in my repo, but when I performed a second push it said everything was up to date, then when I did clone the repo again to try it all over again the files were there in my clone so it seems to have actually worked. I don’t know git as well as I thought I guess…

This is where it got a bit more tedious, when I setup HTTP access following the manual I setup for http access:

https://git-scm.com/docs/user-manual#exporting-via-http

Now I could pull this without authentication but that pulled an empty repository. What was going wrong? Maybe my git setup was wrong so I restarted everything, removed the directory. As a side note I have also added the apache config for that directory here:

http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/

Anyway, back to the drawing board. So I started again but instead I just FTP’d my local copy up to the server to get started. This took a while which provided some reassurance it was working. So once the upload was complete, like most tutorials tell you to, I run:

git init --bare
git config receive.denyCurrentBranch ignore
cd .git/hooks

nano post-receive
GIT_WORK_TREE=../ git checkout -f
chmod +x post-receive

I only uploaded the actual files and not any git files or .git as I didn’t want to muddle things up. But alas, I’m still getting this issue where if I clone the http address, I get an empty repo. Back to the drawing board again and this time I decided “RTFM”.

https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

Okay so this was more insightful, there are two types of git repo’s, one which is declared by bare which is your server directory which is shared and another without which is your clients. I followed section 4.4 and setting up the git protocol and well… it worked. Damn, now I feel stupid, this is a bad article, sorry folks! Well, at least I learned quite a bit.

Main lesson here: Read The Manual – RTFM.

Tags:

Git

Leave a Reply

All fields marked with an asterisk (*) are required