5

I have just started trying to learn Git and I have got a little stuck. We are using Github to hold our "stable" project but I am having trouble working with the repo.

I want to know if its possible to use a local webservers htdocs/[projectname] as the working directory - this way I could clone the repo from github, work on it on the local server ( so it works as the application should allowing me to test everything i write properly ) and then stage -> commit from there.

I am working on a Mac using the MAMP environment. The application is a PHP based CMS. We are holding it on Github on a private repository. Currently Git seems to be using /Users/Ben/Core-CMS as the working dir but this makes it very hard to test things out - it would be much better if the working dir was inside the apache htdocs dir

I bought Pro Git but I am having a very hard time learning the concepts of git - I have purposely avoided using the GUI's as I wish to learn the inner workings of Git properly before I start 'cheating'!

Benoit Garret
  • 14,027
  • 4
  • 59
  • 64
Ben Duffin
  • 1,066
  • 10
  • 16
  • Could you give more details about your setup? (where's your working dir, language/framework you're using, etc) – Benoit Garret Oct 26 '11 at 11:49
  • Sure - I am working on a Mac using the MAMP environment. The application is a PHP based CMS. We are holding it on Github on a private repository. Currently Git seems to be using /Users/Ben/Core-CMS as the working dir but this makes it very hard to test things out - it would be much better if the working dir was inside the apache htdocs dir. – Ben Duffin Oct 26 '11 at 12:04

2 Answers2

7

If you have the permission to write in the htdocs dir, just move /Users/Ben/Core-CMS to htdocs/Core-CMS and access it at http://localhost/Core-CMS.

If you cannot write in the htdocs dir, I'd create /Users/Ben/web, put my projects in there and tell apache to serve from there. To tell apache to look in /Users/Ben/web to serve your projects, look for the following line in your apache conf:

DocumentRoot /path/to/htdocs

and replace it with:

DodumentRoot /Users/Ben/web
Benoit Garret
  • 14,027
  • 4
  • 59
  • 64
  • Seriously? I didnt think it would be THAT easy! Thank you very much :) – Ben Duffin Oct 26 '11 at 12:40
  • A git repo is just a dumb directory with a `.git` inside, the underlying data structures are really simple. – Benoit Garret Oct 26 '11 at 12:42
  • 1
    Note that you should stop your web server from serving the `.git` directory, which contains private configuration information (and all your work-in-progress). If you don't want to have to explicitly do that (and risk forgetting) you might consider setting up a bare repository which deploys on being pushed to, such as described here: http://toroid.org/ams/git-website-howto – Mark Longair Oct 26 '11 at 13:38
  • Our development server is protected with HTTP auth - but this is duly noted! I will add to the exclusion list in apache – Ben Duffin Oct 26 '11 at 14:22
1

This should not be a problem. I'm doing this all the time.

Switch to your public directory and run:

git clone REPO_URL NAME_OF_DIR_TO_CLONE_TO

first.

The dir where you clone a git repository must not exist.

You just need a ssh key authorized to push your changes from the repository to github and git installed on the server (or in your client if you have mounted everything to your local machine).

Then you do you commit which is just local and if you are done you may push your changes to github.

Another way would be to make the webserver use your working directory as its DocumentRoot.

I hope I didn't miss your problem here ;)

Nicolás Ozimica
  • 9,481
  • 5
  • 38
  • 51
Hikaru-Shindo
  • 1,891
  • 12
  • 22
  • Thanks - quick question - when you say "The dir you clone a git repository have to not exist." what exactly do you mean? That a dir with that name cannot exist in the clone path? – Ben Duffin Oct 26 '11 at 14:23
  • If you clone a git project like this "git clone URL abc" it is not possible to have a directory named abc - not even an empty one - already there since it will be created. Git will throw an error message if you try something like this. – Hikaru-Shindo Oct 26 '11 at 14:27
  • So - just to check this is correct - if I clone a Git repo to a named dir on my Mac, to work with that repo in Git again ( say, tomorrow ) then I would just need to navigate to that dir in terminal and git will know what repo it is? because i seem to have problem that git always forgets what project I had open and I cant find an 'open existing' commend ( im not even sure that is what i am after either to be honest! ) – Ben Duffin Oct 26 '11 at 14:48
  • Correct since the information which repository it is are stored in the .git directory inside your clone (in svn you would say working copy) and git will look for this .git directory in the working directory (pwd). I usally do this on GNU/Linux systems but MacOS should behave the same way. – Hikaru-Shindo Oct 26 '11 at 15:15