DEV Community

Dave Kang
Dave Kang

Posted on

Misadventures in Installing Git

I tried to install Git on my mac. I'm a beginner. I encountered difficulties. Here's what happened...

I'm starting a new website project and want to learn some new skills. I know enough HTML and CSS to make a functional but not-best-practice static website. My ultimate goal is to build the site with Hugo, and deploy on Netlify, because all the cool kids are doing static site generators on Netlify.

But before I can use Hugo or Netlify, I need to first get Git up and running. For those of you who don't know what Git is, it's this special software that keeps track of all your programming mistakes, and all your various attempts to fix them. I used Git on a project once, maybe 6 years ago, but I had a real programmer who knew what he was doing help me install it, set it up, and teach me how to use basic commands. I don't really remember how to use Git. Something about pushing and pulling and ignoring but I don't really remember.

Anyway back to the story. Like all good programmers I start by Googling "How do I know if I have Git installed"? That led me to my first command. You have to open your Terminal and type in:

git --version

Then hit enter. That tells you if you have Git already, and which version it is.

Well it turns out the mac installs Git along with xCode, so if you have xCode installed, which I did for some reason (I don't remember installing it), your mac probably already has Git. Doing a "git --version" in the Terminal results in something like:

git version 2.7.0 (Apple Git-66)

Now it's so nice of Apple to automatically install Git for you, but it's not so nice of Apple to for some reason install an older version of Git. Meaning no matter when you install xCode, apparently you will always get an outdated version of Git. I get that it's hard to keep up with software like Git that seems to release new versions somewhat regularly, but the problem is that Apple's version isn't just a tenth of a decimal point versions behind, it appears to be quite a few decimal versions behind.

For people like me who are casual programmers this probably doesn't matter as even older versions of Git probably do everything I'll ever need, but if you're like me there's something annoying about using outdated versions. You just feel... behind. I want to be on the cutting edge of casual hobbyist programming. I want the latest and greatest version.

Looking for the latest and greatest Git

Which takes us to part 2 of our Git install journey -- if the Apple xCode version is outdated, where might one find the latest version? Well at the Official Git Website of course! So I download the Mac installer to my desktop, double click on it, run the installer like any other software I'm trying to install, and SUCCESS!! It's installed. Yay I'm on the latest version! I open Terminal and do another:

git --version

and this is where things get unhappy. It still spits me back:

git version 2.7.0 (Apple Git-66)

Wait a minute. I just successfully installed the latest official version from the official people who make Git, so why is it still showing me the old Apple version? Time for more Googling: "how do I get Mac to use official Git and not Apple Git?"

Some people smarter than me have figured this out. The problem is your $PATH they say. What the heck is a $PATH I say. And why does it have a dollar sign? I'm hoping it's the $PATH to $RICHES when I get all this stuff working. Technically speaking, I don't really know what the $PATH is or how it works, but apparently it's the order in which your computer looks into the gory innards of your computer to do programmy stuff. It starts with your computer's esophagus, them moves to the stomach, then the small intestine, then the large intestine, then the duodenum, until out pops the stuff you want. Ok seriously though, your $PATH tells your computer to look in certain folders, in a certain order, to know how to execute things. Why do we need a $PATH at all? Why doesn't it just work like the user friendly GUI on mac, where if I need something, I just go to that folder and double click it? I don't know, and I don't have time to find out, I just know my $PATH is messed up, and it's using the wrong Git.

Googling this topic results in some interesting advice, that takes you into the murky intestines of your computer, where your nice GUI mouse is of no use here. Just out of curiosity, if you want to see your PATH, type this into Terminal:

echo $PATH

It will spit you back something really sensical and user friendly like:

/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

Apparently this path is the order in which my computer looks through its intestines for stuff, and it's also where my problem lies (although what I pasted above is the fixed $PATH version so you smarty pants people might read my PATH and not understand why I have a problem. FYI I'm doing this DEV.to post after I've figured all this stuff out and I don't know what my $PATH used to say).

Anyway, advice on how to correct this situation leads me to one of my biggest frustrations with software engineering:


In programming there is no one right way to do something, and there are 100 wrong ways


Googling for help produces these results:

-Some people say use "vi" or "nano" to edit your $PATH file. But what the heck is "vi" and "nano"?

-Some people say use the "mv" Terminal command to move/rename the new git to the Apple git, but I didn't like this option because I don't know what this is actually doing. Is it writing over the old Apple Git? Is it moving it ahead of the Apple Git in the path? If I upgrade Git in the future, does this mv thing stay intact?

-Some people say edit your ~/.bash_profile file to add a path to the new Git so your computer looks for the official Git before the Apple Git. But this tends to come with dire warnings that you can mess up your computer and you'll have to buy a new one if you don't do this right, so I'm scared. And why is this file named so strangely: ~/.bash_profile? What's up with that tilda-slash-dot situation at the front end of this name? I found out the dot means this is a hidden file, so you can't find it on your computer, because Apple knows hobbyist programmers shouldn't mess with this file. The slash means if you edit this incorrectly you'll never be able to find it again. The ~ is a symbol that represents the large intestine of your computer, which is where this file resides.

-Some people say screw all that because come on, it's 2019, messing with your computer's intestines is outdated advice, and just use this Terminal command:

brew install git

Wait what? I can just do this one command and it takes care of my intestinal tapeworm for me? I'm in.

But what the heck is brew?

Part 3 of our Git install journey finds me in this situation:

-I've installed the outdated version of Apple Git via xCode
-I've installed the latest greatest version of official Git
-I have these 2 Gits installed deep in the bowels of my computer. I want to use the Official Git, but my computer keeps using the Apple Git.

Enter Brew.

Here and there on the internets you will find people saying to use Brew. What is Brew? Well some Googling reveals a website from the makers of Brew. It says Brew is "The missing package manager for macOS (or Linux)".

I don't know the history of Brew, but I assume it came into being because programmers realized that installing all kinds of tapeworms into your computer's intestines gives it all kinds of digestive problems. Outdated versions of Apple Git, for example that refuses to let the newer cooler official version of Git be used. Brew apparently helps you install stuff, and takes care of all your tapeworms. I like the idea of Brew because I assume the brew-meisters who made it are much smarter than me. I'm gonna try it.

According to the website, you install Brew by simply putting this into your Terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Dev.to automagically makes that URL above a link, and I don't know how to make it not a link, so just ignore the clickability of it. I have no idea what this command does but entering it starts spitting out a long list of stuff, which I try to read but it's flying by kind of fast, and I mostly do not understand it anyway. You need dependencies. OK. You need other packages. OK. It's installing stuff here. OK. It's installing stuff there. OK. Part of me worries about new tapeworms, like I thought I was only installing Brew but Brew is brewing up all kinds of other stuff to install too. I cross my fingers trusting that the Brew-meisters must know what they're doing, so this is probably still a better option than me trying to install all this stuff myself.

It finishes. I have Brew.

I try in Terminal:

brew install git

More matrix-like gibberish text flying by. But it succeeds. Awesome, I now have Git installed via Brew, version 2.23.0.

I try in Terminal:

git --version

It spits back:

2.22.0

Awesome! It's not using the Apple Git any more! I'm in busine--wait a minute? Brew just installed 2.23.0 so why does it say 2.22.0???

2.22.0 is the Git I installed from the official makers of Git website. And now Brew helped me displace the Apple Git with the official Git. Well I guess this is progress, at least it's now using the non-Apple Git, which is what I wanted, but now I have a new problem. Brew installed 2.23.0 not 2.22.0. I want the latest and greatest. I want 2.23.0 to show up when I type "git --version".

Now if I can only get my computer to use the right Git aka third time's a charm

If you're still reading I now have this situation:

-I've installed old Apple Git, which is now not in use
-I've installed Official Git 2.22.0, which is now in use
-I've installed Brew Git 2.23.0, which is not yet in use, but I want to use

So what now?

More Googling. I discover that Brew has this cool feature for amateurs called the "Doctor". It will diagnose your tapeworms and tell you how to get rid of them. Awesome. I enter into Terminal:

brew doctor

It spits back a few things I have to fix, for example something about xquartz being outdated, which I follow the instructions to fix. Done. Great, and lo and behold, there are a couple problems highlighted that are related to Git. Great, finally some insight!

The first one says:

Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link git'

I try typing into Terminal:

brew link git

but it still throws me an error, which I'm sorry I failed to write down. Doing:

git --version

is still pointing me to 2.22.0, which is not what I want. I want 2.23.0.

I find online some people say to try closing and re-launching the Terminal, because apparently the Terminal isn't smart enough to realize something new has been installed. I try that to no avail.

My new error is saying something like this, it's not the exact error because I failed to write it down, but it's in this general format:


Error: Could not symlink bin/git-upload-pack
Target /usr/local/bin/git-upload-pack
already exists. You may want to remove it:
rm /usr/local/bin/git-upload-pack

To force the link and overwrite all conflicting files:
brew link --overwrite git

To list all files that would be deleted:
brew link --overwrite --dry-run git


I decide to try the first suggestion to remove the offending item:

rm /usr/local/bin/git-upload-pack

It's removed. I try again, I get the same error, except now there's a different item causing the offense. I remove that. Try again. Same error, except now it's a 3rd item causing the offense. I wonder how many offensive tapeworms there will be in this list, so I decide to try Brew's second suggestion to "force the link and overwrite all conflicting files". This seems like it might cause some serious damage. I'm a little worried. What exactly is it overwriting? What if I get the Brew Git and Official Git intertwixably messed up somehow?

I look at the 3rd suggestion to "list all files that would be deleted". I google "brew dry run" and discover that it does this: "Show what would be removed, but do not actually remove anything." Hmm this sounds good. I can at least see what I'm about to destroy in my intestinal wall.

I do in Terminal:

brew link --overwrite --dry-run git

It shows me maybe 30 or 40 things that are going to be changed. Ok I now know that continuing on the "rm" remove files one-at-a-time path would have taken me all day to do manually one at a time. I take a deep breath and decide to use the nuclear option. I type into Terminal:

brew link --overwrite git

I then try in Terminal:

brew link git

I can't remember what it said, but it was good news. I then try in Terminal:

git --version

It spits back:

git version 2.23.0

SUCCESS!!! I'm finally using the latest, greatest, Brew installed version of Git. Phew. Next post will be about setting up Git.

Top comments (0)