2

I recently bought a MacBook Pro. I noticed that it comes with git pre-installed. This was not patched version of git. So after following certain tutorials, I used the following steps to update the git to the latest official distribution

  1. I installed Brew
  2. I ran the following command from brew

    brew install git
    
  3. Though when I ran the command git --version from the terminal, I was still pointing towards the previous version.

  4. I updated my path variable to point to my new official distribution git.

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

After this, I have seen my version is updated to the correct version. I have the following queries:

  1. Did I lose my offical mac version of git? If not, where is the mac version of git installed?
  2. I did not set the git environment variable in my bash profile, still when I close the terminal and re-open it, git version is correctly shown.
    1. How can i update my bash_profile to start reading from my newly installed git version?
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
benz
  • 4,561
  • 7
  • 37
  • 68

1 Answers1

4

Did I lose my offical mac version of git?

No.

If not, where is the mac version of git installed?

/usr/bin/git. You can find all instances of git in your PATH with which -a git.

I did not set the git environment variable in my bash profile, still when I close the terminal and re-open it, git version is correctly shown. How can i update my bash_profile to start reading from my newly installed git version?

You've only set the PATH for that current instance of the shell. You need to set it in your shell config.

You can edit ~/.bash_profile and add the same line you used in your shell: export PATH=/usr/local/bin:$PATH. But you shouldn't have to, /usr/local/bin should already be in your PATH, that's why brew uses it. It's possible you installed another version of git in front of /usr/local/bin (which -a git will tell you).

Try running brew doctor. See the brew troubleshooting guide for details.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • Thanks a ton for your wonderful answer. Just a small question, we don't need to add something like GIT_HOME at all. – benz Jan 29 '17 at 11:05
  • @benz AFAIK there's no such [Git environment variable](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables). You shouldn't have to do anything Git specific to use the brew installed Git. What sort of thing are you looking for? – Schwern Jan 29 '17 at 11:29
  • Schwern, i got it now, there is not GIT variable. Actually once i have installed git and appended on the path variable. I closed my terminal and shut down my PC and restarted it, it picks the newer version without adding it into the ~./bash_profile. This is confusing me. – benz Jan 29 '17 at 11:55
  • @benz [There's some things your shell loads every time a new shell starts, and there's some things it loads when you login](https://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment#416931). – Schwern Jan 29 '17 at 19:34
  • hey schwern, i guess i was not able to explain in previous comment. As you instructed, i need to add it in my bash_profile, the path, so that next time the profile is loaded, my path picks location to new git. I did not add it to the bash_profile, even then when i restarted my computer or shut it down, the terminal was able to look into correct version without adding it to my profile. – benz Jan 30 '17 at 08:07