1. [Tutorial] Git server on Mac OS X

    Setting up a public git repository on Mac OS has a few tricks and here’s a step-by-step
    tutorial to the rescue. I needed to set this up for my own projects and most of the information was scattered across the web.

    image

    Let’s roll!

    On the server

    1. Install git. I’ve used both http://code.google.com/p/git-osx-installer/ and the one from Mac Ports. Both work fine.

    2. What’s your public IP? Ah, I know: http://www.whatismyip.com/
    If your server is behind a router, as in my case, you’ll need to setup port forwarding. Port 22 for SHH, to be precise.

    3. SSH is installed by default on Mac OS. It’s accessible from Terminal, you can generate keys, but it doesn’t allow other computers to connect to your server. To enable this go to System Preferences -> Sharing and from the list on the left, check “Remote Login”.
    We’ll come back here later, because it allows some more advanced settings.

    4. Create a user that will manage the repositories. The simplest way is trough System Preferences -> Accounts. Create it as an
    Administrator for now, and you can remove the Administration rights later on. It will make the installation easier. Let’s name it ‘git’ to remember it easier.

    5. Generate an SSH key by typing the following in Terminal:

    6. Setup pasword-less ssh. This is a very important step and you should not continue with the next steps if this doesn’t work.

    For this, you need to generate an ssh key from your client machine, exactly like on the previous step.

    The generated key will be a one-liner in ~/.ssh/id_rsa.pub. Copy this key to the server inside /Users/git/.ssh/authorized_keys.
    Create the authorized_keys file if it doesn’t exist already. To check the setup, from your client machine run:

    If it logs in w/o asking for a password, you’re the man! Otherwise, double check if the public key from the client corresponds with the one from the server.

    7. gitolite enters the scene.

    “Gitolite lets you use a single user on a server to host many git repositories and provide access to many developers, without having to give them real userids on or shell access to the server. The essential magic in doing this is ssh’s pubkey access and the authorized_keys file, and the inspiration was an older program called gitosis.

    Gitolite can restrict who can read from (clone/fetch) or write to (push) a repository. It can also restrict who can push to what branch or tag, which is very important in a corporate environment”


    Run the following commands in the command-line:

    As a quick walkthrough, this downloads the gitolite repository, creates some required directories and runs some config scrips.
    The path on the last line might vary, depending on how you named your user account that handles git.

    The above scripts also create a test repository in /Users/git/repositories/

    8. Do the victory dance, because you now have a git server on your Mac.

    On the client

    1. Install git, the same way you installed it on the server.

    2. Navigate in Terminal to the location where you want the repository to be and grab the test repository by running:

    3. Pushing your commits to the server might require some special settings. Since there are too many options, I won’t get into these details here. This is a link that might help: http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked-ou . Do remember to contribute with at least an upvote if you found the information useful. Be nice to Stackoverflow and it will be nice to you.

    Happy remote coding!

  2. How to find items that have a certain pattern in their name

    While backing up my Mac Os today I found the need to mass copy some files and directories from my home folder. Most of them contained a certain pattern so this helped a lot.

    List of directories that start with “wo”:

    find . -maxdepth 1 -type d -regex “.*/wo.*”

    List of files that end with “rk”:

    find . -maxdepth 1 -type f -regex “.*/.*rk$”

    Copying to /destination/path/ all directories that contain “foo” in their name:

    find . -maxdepth 1 -type d -regex “.*/.*foo.*” -exec cp -r {} /destionation/path/ \;

    In the above command lose the -r after cp and replace -type d with -type f to perform the same action, but on files.

    1. Tiffany:Hey, your Mac looks like a noir movie, what gives?
    2. John:Go to “System Preferences”, “Universal Access.” Set your display to “Use grayscale.”
    3. Tiffany:Oh, Mister Bogart!