3

So basically i'm tryiing to update git on my Mac, i'm using VScode with one of the terminals propped up as powershell, and so i check the version of it using the command

git --version

What I got from it was

git version 2.15.0

So I had assumed that I hadn't updated it so I went along and used the command

brew upgrade git

and I get a response saying "Warning: git 2.34.1 already installed", and I check up on it again and the git version is still at 2.15.0

Any thoughts on how I could fix this?

  • The root of the problem is that `brew install` installs an *additional* Git version, so now you have both Git 2.15.0 and Git 2.34.1. This means you must direct whatever is going to run `git` to look for the brew-installed version *first*, before looking for the system-installed version. As [VonC answered](https://stackoverflow.com/a/70782497/1256452), there are multiple ways to make this happen. – torek Jan 20 '22 at 18:14

2 Answers2

5

Hey guys thank you for all those who commented what to do and what's going on, so ultimately while playing around with it for a while this was what I was able to do!

So I go into my terminal and ran brew install git

After that I got this reply in the terminal as follows

Linking /usr/local/Cellar/git/2.34.1... 
Error: Could not symlink bin/git
Target /usr/local/bin/git
already exists. You may want to remove it:
  rm '/usr/local/bin/git'

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 

So I went and ran the command

brew link --overwrite git

The reply i got was :

Linking /usr/local/Cellar/git/2.34.1... 213 symlinks created.

Ran the following command afterwards

brew link --overwrite --dry-run git

Got the following reply back :

Warning: Already linked: /usr/local/Cellar/git/2.34.1

To relink, run:
brew unlink git && brew link git

So I finally ran a check to see what the git version was

git --version

And I got the updated git version I was trying to get my path aligned to!

git version 2.34.1

Hope this helps anyone else who needs help with this! I did not remove '/usr/local/bin/git' but hopefully I didn't need to or won't have to worry about it later on.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
1

You would need to make sure homebrew/bin folder is first in your $PATH (on macOS Monterey):

export PATH=/opt/homebrew/bin:$PATH

Then a git --version would return the expected latest version.
You have various options explained here, like adding alias git="/usr/local/bin/git" to your .zshrc or .bashrc.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • When i enter the command im given a reply of "export: The term 'export' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." – Jahanzeb Ahmad Jan 20 '22 at 07:56
  • 1
    @JahanzebAhmad First, make sure you have a macOS Monterey. Second, that line is to be added to your `~/.bashrc` or `~/.zshrc`. Then open a new session and launch VSCode, in order for that IDE to inherit from the new PATH. – VonC Jan 20 '22 at 07:58