0

I installed Git 1.7.7.4 by homebrew, but Apple integrated Git into Xcode since version 4. So in my computer, the default Git version is 1.7.5.4 which it's built-in Xcode 4.

I wonder if there's a way that let me use new version by default and would impact Xcode?

I tried add the path to $PATH:

export PATH=/usr/local/Cellar:$PATH

BTW, I'm using zsh.

Updated: Thanks for @birryree's help, I'm using a wrong path, it should be /usr/local/bin, because of homebrew will use /usr/local/Cellar for storage, and use symlink to make sure all the packages are available on /usr/local/bin.

Chris
  • 1,264
  • 1
  • 10
  • 14
  • 1
    It's in `/usr/local/bin`, but I don't know if xcode hard codes using the one it installed into `/usr/bin`. – wkl Nov 21 '11 at 16:01
  • Well, homebrew installed Git under /usr/local/Cellar and set a symlink for it, so I guess should be Cellar. Xcode does hard code using the /usr/bin. I hate it... Thinks for your help. – Chris Nov 21 '11 at 16:06

6 Answers6

2

There is a much easier way. In your shell's profile file (.bash_profile, .zshrc ect...), make an entry is its not already there:

export PATH="/usr/local/bin:$PATH"

That will tell the shell that all packages installed by homebrew will override system defaults since homebrew creates aliases in that directory which points to your Cellar.

bmoran
  • 1,499
  • 2
  • 13
  • 21
1

Run the following command:

brew link --overwrite git

This should make sure that the symlink happens and the right version of git is being used.

Barry
  • 11
  • 1
  • should be the accepted answer. In my case brew said it was already linked so I had to brew unlink git && brew link git – maaw Sep 16 '22 at 18:50
0

According to my experience with my problems, have a check at 10449374 and 13177203, this will help you:

  1. change into the Xcode directory:

    cd /Applications/Xcode.app/Contents/Developer/usr/bin

  2. rename the Xcode's git like this:

    sudo mv ./git ./git-xcode-usr-bin

  3. link my own git which is installed through homebrew:

    sudo ln -s /usr/local/bin/git ./git

And you should do the same thing with /usr/bin/git:

sudo mv /usr/bin/git /usr/bin/git-xcode-usr-bin
sudo ln -s /usr/local/bin/git /usr/bin/git

This will acctually link /usr/local/Cellar/git/1.8.0/bin/git (because I'm use git 1.8.0 at the present)

Community
  • 1
  • 1
oppih
  • 860
  • 8
  • 14
  • It's a horrible, hacky, solution and the OP doesn't even state why he wants to use a newer version of git. Git is fairly broken in Xcode anyway (if you have any kind of merge issues) so I would recommend using SourceTree for all non-trival git operations: http://www.sourcetreeapp.com/ – trojanfoe Jan 23 '13 at 11:56
  • This is way way too hacky tacky to use. It's easier to prepend `/usr/local/bin` to your `PATH` variable; it is originally the last directory listed. Check out this answer ---> http://stackoverflow.com/a/10455668/393021 – Igbanam Jun 04 '13 at 17:48
0

The chosen answer may break when you update xcode.

Instead, add something that looks like the following lines to your ~/.bash_profile

Modulo your git version installed by brew

### Added to use brew git
export PATH="/usr/local/Cellar/git/1.8.1/bin/:$PATH"
mickey06
  • 171
  • 3
  • 7
0

I am using fish shell with oh-my-fish and fix this problem after I set the plugin named brew in config.fish.

For zsh, if you use oh-my-zsh, you can try to go to ~/.zshrc and add plugin named brew like "set plugins=(brew)"

kaitoborn
  • 1
  • 1
0

Does /usr/local/Cellar/git exist?

I'd expect a path like /usr/local/Cellar/bin/git

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820