Different versions of Git on Mac OS Yosemite - macos

I guess Git on my macbook was of version 1.8.4, because I tried
git --version
git version 1.8.4
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
whereis git
/usr/bin/git
later I try to upgrade the latest version of Git to 2.0.1, I download and install from
http://git-scm.com/download/mac
Since this installer installs Git to /usr/local/git, and append the path to $PATH, so now
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin
I also replace the binary file to /usr/bin/ by
sudo cp /usr/local/git/bin/git /usr/bin/
And I logged out and logged in back, but found the following strange situation:
/usr/bin/git --version
git version 2.0.1
git --version
git version 1.8.4
whereis git
/usr/bin/git
Where does my mac os look for when I type git --version? Where is my previous version 1.8.4 located and how can I delete it and replace it with my new version?

The correct way to use another version of git would be to put it first in the path. Edit the file that appends /usr/local/git/bin to the path so that it prepends it instead.
Most likely there is something like the following in either your ~/.bash_profile or ~/.profile.
export PATH="$PATH:/usr/local/git/bin"
Change it to:
export PATH="/usr/local/git/bin:$PATH"
BTW, sudo cp /usr/local/git/bin/git /usr/bin/ is probably not a good idea, as other software may expect the default version to be there. A software update may also replace it.

Related

Can I install/use git on OS X Yosemite without CLDT?

A friend of mine need to clone a git repo, but on his machine is xcode not installed and when he tries to use git his Macbook says
The command git requires the command line developer tools, do you want to install them?
The picture is in German.
So is it possible to use git on OS X without Xcode?
Yes. Instead of using the built-in git command:
Install Homebrew if you haven't already:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run brew update && brew install git
Restart Terminal (or close the current tab and open a new one)
Before you do this:
$ git --version
git version 1.9.3 (Apple Git-50)
After you do this:
$ git --version
git version 2.2.1
How about using SourceTree.app?
http://www.sourcetreeapp.com/
SourceTree.app has also git binary.
$ SourceTree.app/Contents/Resources/git_local/bin/git --version
git version 2.2.1
EDIT
he has github for mac installed and git, but it shows this message anyway :(
I guess he didn't set PATH env, so that git was /usr/bin/git. He should use /Applications/GitHub.app/Contents/Resources/git/bin/git instead of git, or set PATH env.

WARNING: Your version of git is 1.9.3. has serious security vulnerabilities

I received a warning regarding serious security vulnerability of git 1.9.3 during deploy to Heroku
I tried to update git via homebrew but found that git was not originally installed via homebrew
Then I installed it via homebrew
brew update
brew install git
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-2.2.1.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring git-2.2.1.mavericks.bottle.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
/usr/local/bin/git-credential-osxkeychain
The "contrib" directory has been installed to:
/usr/local/share/git-core/contrib
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completion has been installed to:
/usr/local/share/zsh/site-functions
==> Summary
🍺 /usr/local/Cellar/git/2.2.1: 1356 files, 31M
After that when I checked git version it remained the same
⇒ git --version
git version 1.9.3 (Apple Git-50)
It seems to me homebrew installed git in folder /usr/local/Cellar/git/2.2.1
And finally my question:
what should I do to start using homebrew git instead of the original git?
⇒ which git
/usr/bin/git
⇒ git --version
git version 1.9.3 (Apple Git-50)
You need to rename original git at /usr/bin/git, e.g.
sudo mv /usr/bin/git /usr/bin/git-original
Now check location and version again
⇒ which git
/usr/local/bin/git
⇒ git --version
git version 2.2.1
Add a symlink for backward compatibility (in case your IDE uses direct location to git)
sudo ln -s /usr/local/bin/git /usr/bin/git
Like Jubobs commented, you can simply add it to your path like so:
echo 'export PATH="/usr/local/git/bin:$PATH"' >> ~/.bash_profile
Just change ~/.bash_profile to whatever bash profile file you're using.

I can't uninstall Git

I tried to update my git version on Mac OS X 10.7, but it doesn't change the version.
It's still on 2.0.
If I run,
rm -rf /usr/local/git
rm /etc/paths.d/git
rm /etc/manpaths.d/git
the new version gets uninstalled, but the old one is still there (git is still a valid command).
How can I find the directory where this "ghost" version is installed?
To see where git is installed:
which git
See for instance those guides:
"Beginner's Setup Guide for Git & Github on Mac OS X"
"Install and Update to latest version Git on Mac OSX 10.10 Yosemite"
The location usually is:
/usr/local/git/bin/git
As mentioned in "Can't seem to uninstall git":
/opt/local/bin is the location of software installed by macports, so you'll want to run this:
sudo port uninstall git
If you see /usr/local/bin/git, that is likely a brew installation: see "Can't use homebrew installed git":
brew uninstall git
# make sure everything is alright, maybe brew will give you some hint
brew doctor
brew update
brew install git
# magic happen, brew will give you hint /usr/bin occurs before /usr/local/bin
# and recommend you run following command
brew doctor
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

git version and brew upgrade on different versions, no xcode, need fix

which git
gives me: /usr/bin/git
git --version
gives me: git version 1.8.5.2 (Apple Git-48)
brew upgrade git
gives me: Error: git-1.9.0 already installed
So I ask: What's up? and How do I fix it?
This is because you are using version of git that was installed not by brew. Brew stores its git install in the path /usr/local/bin/git You must remove the git that was not installed by brew, or change the order of your $PATHS to check /usr/local/(bin|sbin) first.

Install Git before Boxen, or Boxen before Git?

So, I've just ponied up for a Mac, and I'm looking to use Boxen to get a working environment setup. Thing is, the setup instructions are a little confusing. The intro on this page:
https://github.com/boxen/our-boxen#getting-started
uses git
sudo mkdir -p /opt/boxen
sudo chown ${USER}:admin /opt/boxen
git clone <location of my new git repository> /opt/boxen/repo
cd /opt/boxen/repo
script/boxen
but it then goes on to state:
This template project provides the following by default:
Homebrew
Git
Hub
I get the impression that you ideally want to have a clean system to avoid conflicts when using Boxen, so before I get git from homebrew/app store, I wanted to see how others have gone about setting up Boxen so I can save myself some headaches
I don't think you need to install git first. I've installed Boxen, although I haven't yet tried a clean bootstrap on a new machine. Here's my understanding:
1) The X-Code Command-Line tools are a prerequisite for installing Boxen - X-Code installs a version of git as /usr/bin/git, so there is no need to explicitly install another git to bootstrap Boxen. On my machine - Mountain Lion/10.8.3:
$ /usr/bin/git --version
git version 1.7.12.4 (Apple Git-37)
2) Once you install Boxen, Boxen will then install the Homebrew release of git at /opt/boxen/homebrew/bin/git, which is likely a newer version of the X-Code Command-Line git:
$ /opt/boxen/homebrew/bin/git --version
git version 1.8.0
3) Finally, by default, Boxen will install hub, which will alias git to hub (hub is a GitHub-enhancing wrapper around git):
$ type -a git
git is aliased to `hub'
git is /opt/boxen/homebrew/bin/git
git is /usr/bin/git
$ git --version
git version 1.8.0
hub version 1.10.5
I let Xcode command line tools do it for me, before I setup a fresh Boxen:
$ xcode-select --install
After you setup your Boxen, you'll be up to the appropriate Git version.

Resources