gitrepositoryrepository-design

Is there a preferred path where I should initialise my Git repo on Mac OS X?


Where should I be building my repos? My tutorial repos went to root, but I thought since I would have a test of my production site, that I should build them in ~/sites/.

It might seem trivial, but most introductions to Git I've seen don't really specify a particular location.


Solution

  • When you work with Git, there are multiple repositories you may be working with.

    First, there's the local repository. This is a complete repository that lives on your local system. You must have a local repository to use Git, and everyone who does work with this project will have a copy of this repository locally on their system. It's how Git works.

    Put this local repository wherever you feel like working. In Subversion terms, think of it as the working directory. I have a $HOME/workdir were I put all of my various projects where I work. Some of these are Subversion working directories (for example, ~/workdir/verbox/trunk). Some of these are locally Git repositories. (~/workdir/git-box). This way, all of my work is in one central place.

    Then, a project could have various remote repositories. These are repositories that others have where you push and pull information. The nice thing about Git is that there's not necessarily a master repo. Everyone has a local repository, and you are free to pull or push your changes to other repositories. For example, let's say you're working on a project with Bob. Bob and you would have a local Git repo of this project. When you want Bob to see your changes, you push your changes onto Bob's local repository. If you want Bob's changes, you pull Bob's changes from your repository.

    You might have another repository on Github that will be where you will release your code. Both Bob and you push and pull your changes to and from that repository. There's no master repo. Just repos that have a common history and can share back and forth.

    Speaking of GitHub, if you want your project to be publicly accessible, setting up a Github project is a good idea. No need to worry about administration or firewalls, etc.

    If you want a publicly accessible Git repository of your project on your Mac (something I would not really recommend), then setup a new user. Setup the SSH keys for each user who will have access to this repository, setup your Mac firewall to allow for remote login. And put a copy of your repository for that user. Also setup this user's default shell to /bin/false. You don't want people doing anything with this user other than pushing or pulling their changes to this repository.

    So, what about that Site directory under your $HOME directory? When OS X first came out, there was an idea that web developers would be attracted to it (true), and that they would want to run Apache's httpd daemon on the system. By default httpd.conf was setup to allow every user the ability to have their own webpage on the system. For example, http://localhost/~beta208/... If you put HTTP files under Site, it would be on your local webpage.

    It turns out that this is not how Web developers wanted to operate. In later releases of Mac OS X, Apache httpd doesn't run by default, and the Site directories aren't automatically configured. Turns out that Web Development includes a wide range of stuff, and web developers will setup their own system, thank you very much, without help from Apple. The Site directory is there, but like a vestigial organ, it doesn't really do anything. New users created on Mac OS X don't get a Site directory.