There is a problem with installing Git on OS X: it is already installed on the system and just does not update it. Each time you upgrade the OS, install it again.

For example, at the time of this writing, the current version of Git is 2.5.1. And in OS X Yosemite is sewn up 2.3.2.

When installing a new version through Homebrew, it still remains inaccessible.

    1 answer 1

    Installation from scratch

    1. Install Git, for example through Homebrew

      $ brew install git 
    2. Checking the current version of Git

       $ git --version git version 2.4.9 (Apple Git-60) 

      If you see "Apple Git", then the old version is used. Check where the version of Git is installed.

       $ which git /usr/bin/git 

      Exactly, this version is put together with the system. And the one that we need, and which is installed by homebrew, is located in /usr/local/bin/git . Why is she not chosen? Most likely because the path to it is further in the $PATH environment variable.

       echo $PATH 
    3. Change $PATH

      The $PATH variable stores folder paths separated by colons. When you want to run some program by name (and not by the full path), the search takes place in all these folders in turn, from left to right. The variable is set in the ~/.bashrc (or ~/.zshrc , etc., depending on the shell used). Open it and find something like this:

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

      Put /usr/local/bin before /usr/bin :

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

      Restart the shell:

       bash $ git --version git version 2.10.1 $ which git /usr/local/bin/git 

      Hurray, it works!

    • Rename this folder - the file, probably. - aleksandr barakin
    • @alexanderbarakin: thanks, confused. By the way, are you subscribed to the label? - Nick Volynkin
    • which git - by the way, doesn’t the $PATH environment variable in apple / macos really contain /usr/local/bin to /usr/bin ? // are you subscribed to the label? - yes, the git tag is in my favorites. but I have long refused from email notifications because of their lack of efficiency. - aleksandr barakin
    • @alexanderbarakin: I have this order in $PATH : /usr/bin /bin /usr/sbin /sbin /usr/local/bin . And what, you recommend to change? - Nick Volynkin
    • one
      Unfortunately, this method of renaming / usr / bin / git does not work at macOS Sierra :( the system writes the message rename / usr / bin / git to / usr / bin / git-apple: Operation not permitted Any other ideas on how to remove Apple Git? - user223376