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

14,732

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.

Share:
14,732

Related videos on Youtube

beta208
Author by

beta208

Web / IT Support

Updated on September 15, 2022

Comments

  • beta208
    beta208 over 1 year

    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.

    • drkvogel
      drkvogel over 5 years
      This is something I often wonder - what are the most popular names for a folder where you keep all your work? I don't like using ~/Documents on a PC or a Mac, because it can get cluttered with allsorts of other, non-work/project stuff. I create a ~/Projects folder and keep my git repos in there. But what do other people call it? Poll anyone?
  • beta208
    beta208 over 9 years
    Ok, I wish this had come a few minutes before I made my first repo. I put ~/Repos and init git inside it. Now I'd like to move it to a /Repos/ExampleSite/ how can this be done?
  • jub0bs
    jub0bs over 9 years
    @beta208 Simply move the ~/Repos folder to the desired location. The repository you initialised in that folder will follow it to the new location.
  • David W.
    David W. over 9 years
    The entire Repos directory is your Git repository plus your working directory. That's how Git works. You can move the entire directory tree around and be good. Everything about your Git repo -- files, their history, branches, changes, live in an invisible directory under your repository's directory called .git. Remember: Don't think of these as Repository directories as much as the directory where you do your work.