Created a local working copy... guide to creating a bare clone on my webserver?
Asked by Benjamin Allison:

I'm a total noob to git, and hate (HATE) working in the Terminal (which is why I'm using SourceTree!).

Here's the issue. I've created my local working copy. Everything's humming along nicely. Now what I want to do is create a bare clone on my webserver, and allow SourceTree to push changes to it.

I'm hosting on MediaTemple. They're set up for git, and I've created my subdomain as they recommend ([git.mydomain.com](http://git.mydomain.com)).

The plan is to put the clone in [git.mydomain.com](http://git.mydomain.com), and then push changes which will appear on the live site, [mydomain.com](http://mydomain.com)

I'm hoping to do all this from within SourceTree but am struggling to determing how to actually achieve that. Is this possible? Is there any kind of guide that can walk me through the steps?


Answers:
author: KieranA
body: Hey Benjamin,

Unfortunately you will have to hop on the server via the terminal in order to initialise the remote repository so you can push to it. By whatever option MediaTemplate give you, presumably SSH access via your terminal so you can log in, go to the remote location pertaining to [git.mydomain.com](http://git.mydomain.com) and initalise a bare repository by doing "git init --bare".

In SourceTree you'll then want to add a new remote and specify your MediaTemplate server's URL as the remote. From here you can then push to it because you're probably using the same SSH keys as before from when logging in.

Hope that helps, if not, feel free to ask away!

comments: author: Benjamin Allison
body: Thanks Kieran! That's not sooooooobad. So, do I simply initialize a repo on the server, and then push everything to it, or do I have to clone first?

And one completely random question about terminal/repo addres: so I assume you meant I needed to enter the username/url combination (mydomain.com@s#####.gridserver.com). However, my repo is in a subdomain: [git.mydomain.com](http://git.mydomain.com). How do I specify that in SourceTree, since the MediaTemple server address is mydomain.com@s#####.gridserver.com? Not sure if that's making sense (or how familiar you are with MediaTemple).

Thanks for your help!


author: Benjamin Allison
body: I'm assuming it needs something like this?

mydomain.com@s######.gridserver.com:domains/git.mydomain.com/html/repo.git

However, everytime I add a server URL, it vanishes...


author: Benjamin Allison
body: SoI seem to be getting somewhere:

ssh://username@git.mydomain.com/repo.git

But I'm getting an error when I try to push:

```
fatal: '/repo.git' does not appear to be a git repositoryfatal: The remote end hung up unexpectedly
```

But I know that's the location of the repo I set up server side using git init --bare


author: Benjamin Allison
body: Wow!!! I think it worked? Part of the problem is that I'm using CloudFlare on this domain, so you have to use their "direct" subdomain... along with using the absolute path, not just a URL.

For other people's reference (I'm on MediaTemple GS fwiw):

mydomain.com@direct.mydomain.com:/home/######/domains/git.mydomain.com/html/repo.git


author: Benjamin Allison
body: Sorry, last question:

So, my assumption is that if I want to use Git to manage my actual website, I need to create the base repo IN the appropriate folder?

For example, on MediaTemple, the folder /html/ is where you place the index, etc... on other servers the folder is called "public_html."

I place my repo there? Is there anything else I need to do to make sure pushes are reflected in the files on my server?


author: KieranA
body: Hi Ben,

Sorry, I had seen all of these yesterday but was unable to reply. From your last comment it sounds like you're wanting to push changes to the server and the server should be hosting the website. If the bare repository is the one you want to host the website from, i.e. in public_html, then you can't do that. A bare repository doesn't work like a regular working copy, it doesn't have the files as you see in your repository, it has a completely different structure because it keeps an index, not a working copy.

So, if you want to host your code on your MediaTemple server, just use a bare repository as previously discussed, *but*, if you're looking to host a website in a way where pushing your changes to the server should show the changes, then having a bare repository in your public_html folder just won't work. What you're going to need is a post-commit hook which would run a deployment script to connect to your MT server and either SSH in and copy files over or some other kind of FTP sync script. There's a number of options if you're looking for a deployment solution.


author: Benjamin Allison
body: I think I'm headed in the right direction! Thank you SO MUCH for your quick responses. You've been a huge help Kieran!


author: KieranA
body: You're welcome, Benjamin :)


Tags: clone

push