Wouter Martens

Hi, my name is Wouter... or « wuotr » online. I'm a 28- year old app developer, UX enthusiast and music / movie / serie lover. I'm currently working at iCapps in Antwerp, Belgium.

Use your own GIT installation with Xcode

Are you an iOS or OSX developer? Do you like to keep up with the latest versions of your toolset and software? Then you might find this useful ;-).

Personally, I like to work with the latest version of GIT constantly. So I'm managing my own GIT installation through Homebrew. This (awesome) package manager installs its software, like most of you know, in the /usr/local/Cellar/ directory and creates symlinks to /usr/local/bin/. This is all perfect.

But Xcode however, comes with its own (older) version of GIT inside the Xcode.app package. Also, the same version of GIT gets installed in the /usr/bin/ folder when you install the Xcode command line tools. So in order to use the Homebrew GIT installation with Xcode smoothly, I'd suggest two things:

  1. Change the path as PATH=/usr/local/bin:$PATH either in your .bashrc or .zshrc file (if you are using ZSH). This way you don't have to do so each time you start a terminal at the command line.

  2. You can change the GIT installation of Xcode inside the .app package in order to avoid inconsistencies between different GIT versions. And it's actually quite simple…

Open up your terminal and cd to the /Applications/Xcode.app/Contents/Developer/usr/bin/ directory. List all the files inside this dir & you'll see Xcode's GIT executables. Rename these files by appending "-back" or something else you find more tasty:

  • git => git-back
  • git-cvsserver => git-cvsserver-back
  • git-shell => git-shell-back
  • git-upload-pack => git-upload-pack-back

Remember you're inside an application package. You should use the "sudo" command upfront, otherwise OSX won't let you change anything. To rename the git file for example, execute this little line: sudo mv git git_back

Now you can create symlinks to your GIT installation inside the /usr/local/bin/ directory, wich in turn will link to /usr/local/Cellar/. For example… to symlink the git file itself, you have to run this command: sudo ln -s /usr/local/bin/git git

You should do this for all these files:

  • git
  • git-cvsserver
  • git-receive-pack
  • git-shell
  • git-upload-archive
  • git-upload-pack

And that's it ;-). You are good to go now. An overview of your files should look like this:

So if you decide to upgrade your GIT installation through Homebrew sometime in the future; Xcode will automatically use the same (upgraded) GIT version as well. This is because the GIT installation inside /usr/local/Cellar/ gets upgraded, but the symlinks in /usr/local/bin/ stay the same.

Great! Isn't it?

Note: There's also one downside with this setup. You'll have to symlink the GIT executables again every time you install a new Xcode version because the whole .app folder gets replaced. But that's a small pay-off compared to all the advantages you get methinks ;-). And Xcode doesn't get updated as fast as GIT anyway.

Now go back to work and build something cool! Happy coding…