Install Git Mac Osx

broken image


Background

I'm doing a bit of web development work, for myself and for my clients, and realised that having some form of source control will be quite useful.

Subversion

I initially looked at Subversion which has a lot going for it.

  • It's built in to Mac OS X and Mac OS X Server.
  • There is a large variety of GUI clients for it.
  • It's built into Dreamweaver, Coda, Textmate and quite a few other pieces of software.

The downside that I didn't like is that it's quite rigid with it's management of files. If I'm collaborating with someone else on a project and they, for example, send me a new folder of images for a project, I can't just delete the old folder of images and put the new one in it's place. There's a hidden .svn folder in each folder that holds important information and if you delete this, Subversion gets a bit annoyed. If you're working with someone on a project and they don't have access to your repository (for example if it's on an internally accessible server that's not published to the Internet) then it's a lot tricker to merge changes back and forth.

Really though, it was the lack of being able to manage my files and folders easily in the Finder without worrying about not being able to check it back in again that put me off it.

Mac running OS X 10.7.5 and Git is not installed in my machine, presumably. In Terminal, git -v yields '-bash: git: command not found'. Can't proceed with Installing a Ruby Development Environment module until I have Git installed. There's a common issue with git and 10.7.5. It's likely that your OS version and the git version you're trying to install are incompatible. There are three ways to tackle it: Upgrade your OS to the latest version, then install git.

There are a couple of ways to install Git on MAC OS. The easiest way to do it would probably be to install the Xcode Command Line Tools. This will work on Mavericks (10.9) or above, so it should cover you.

Git

Installing Git on a Mac Open a terminal window. Step 1 – Install Homebrew Homebrew simplifies the installation of software on the Mac OS X operating system. On a Mac, it is important to remember to add.DSStore (a hidden OS X system file that's put in folders) to your.gitignore files. If you want to never include.DSStore files in your Git repositories, you can configure your Git to globally exclude those files.

My next choice then was Git. This is a more distributed version control system, not only does it not need a server but there's no one standard type of server software to run either. I can grab a folder that's managed by git, email it to a colleague and they can merge it into their git repository quite easily. They can also export their copy and it's quite easy for me to merge it back into my version.

There are some good Git clients for Mac OS X, such as Tower. Tower is in public beta at the moment, but is quite stable and usable. Git is also baked into Textmate as well which is my editor of choice.

Git Servers

Os X Installer

As I'd decided that I wanted a Git repository, I then wanted to set up a proper Git server on my Mac mini Server. Well, this is easier said than done.

I initially wanted a Git server that used the git protocol (git://server…) running on port 9418, but this is definitely not easy to achieve. The options seem to be limited to the git-daemon which by default only has anonymous read-only access to the projects (or, if you enable write to the projects, it's anonymous write access only) and running a private version of GitHub, known as GitHub:fi. I'm sure GitHub:fi is quite good and at $2500 it'd want to be, but I'm not shelling out that kind of money for a side project.

As an aside, there are a large number of publicly hosted git servers, but I want to keep this work inhouse at the moment.

The short answer however is that it's not at all easy to host a 'proper' git server, one that's accessible via the git:// protocol. It seems that the next most popular option (and one that's also nice and secure by default) is hosting a git repo over ssh and there's also options for hosting git repos over http (or WebDAV)

After looking at the other options, I've had a go with Gitolite which is a relatively easy way to set up the environment you need on the server to host git repos via ssh.

Gitolite

Gitolite is an open-source project, hosted on GitHub. It's pretty easy, if you have even a working command-line git client, to download the source and set things up. It's based on a very similar project called Gitosis, but Gitolite seems to be under active development whereas Gitosis seems to have been left alone for a while.

Install

Installation on Mac OS X Server

Create a user to host the repos.

Using your tool of choice, either Server Preferences or Workgroup Manager (or, if you're hardcore, the command-line) create a user for the git service. In order to keep things straightforward, I called this user git. This user can either be created as a local user or in the directory, it doesn't really matter. I set their home to be /Users/git and told Workgroup Manager to create their home directory. I initially made the user an Administrator as this made the install process easier (I had access to sudo as the git user for example) and then once it was all set up, I turned off administrator permissions for this user.

Install Git.

There are two options. If you have the Developer Tools and MacPorts installed, you can simply type in to the Terminal

As I didn't have all of this installed on my Server, I took the easy path of installing git as an OS X package.

Once git was installed and working, I could then check out the source tree for Gitosis.

Set up Passwordless ssh

You'll will need to set up public key authentication for ssh. Copy your ~/.ssh/id_dsa.pub or id_rsa.pub file to the server in the git user's .ssh directory as authorized_keys, or use the

Clone the source of Gitolite

This is pretty easy to do:

Install Gitolite

Installing gitolite was pretty straightforward – simply following the instructions in the download. You don't need the developer tools or anything like that installed. Gitolite is a bunch of scripts that sets things up for you, not some code that needs to be compiled to run.

Simply execute:

on the server and you're on your way. Alternatively, on your workstation, you can clone the repo and run

and this will set things up on the server for you.

Set up the user's environment

One thing I found with the base install on Mac OS X was that the $PATH environment variable wasn't set correctly for non-login shells. You can easily check what the default path is on the server by entering the following on your workstation

On my server, this was returning a path that didn't have the git binaries in it, so I couldn't check out or do anything else.

Simply by editing .bashrc for the git user on the server and adding in the following;

This was enough to fix this simple problem. If you don't want to edit the .bashrc file, you can specify the git binary directory in the command line invocation, but I'm not sure this'll work with a GUI client:

Further Reading

There's a really good writeup on 8 different ways to share your git repo from Patrick Debois that has a quick overview of the pros and cons of a heap of different ways to share your repository.

In this tutorial, I will go over the instructions to setup a git server on Mac OS X. Here, I will assume that the server IP address is 12.34.56.78.

Install Git Mac Osx 10.13

First, you will need to add a user named git

Git For Mac

, into which client machines will ssh into. To do so,
1. Open up System Preferences -> Users & Groups.
2. You may need to click the Lock image to make any changes.
3. Click on the + button to add a user.
4. Add a standard user whose full name and account name is git. Enter password.
5. Click on Create User button.
Next, you will need to allow ssh login for user git from client machines. To do so,
1. Open up System Preferences -> Sharing
2. Check Remote Login box.
3. Add the user git in the Allow access for field by clicking on the + button.
From your client system, make sure that you can remote log into the server's git account.
$ ssh git@12.34.56.78 -p 22
Note that here I am assuming that you are using the port 22 to access the server. Depending on your router or firewall configuration, the port number may differ.
If you can successfully log into the account, then you are pretty much done. Let's assume that you will want to create a repository named Project. From the git account from the server or through ssh, run
$ pwd
/Users/git
$ git init --bare Project.git
This will create a bare Project repository on the server, which clients can clone, push to, and pull from. The location of this repository in this case is /Users/git/Project.git, as you can see from pwd command above. To clone this repository from a client, you will need to run the following from the client
$ git clone ssh://git@12.34.56.78:22/Users/git/Project.git
You will need to enter the password for the server's git account, as if you are remote logging into it through ssh. You should now have a personal git server.
Note: If you are concerned with safety, you may want to disable password login and instead only allow public key authentication. I will cover how to do so in the future post.



broken image