7

I cant delete or rename current version of git... Even with sudo...

MacBook-Pro-Kiril: $ sudo rm /usr/bin/git
override rwxr-xr-x  root/wheel restricted,compressed for /usr/bin/git?

MacBook-Pro-Kiril: $ sudo mv /usr/bin/git /usr/bin/git-apple
mv: rename /usr/bin/git to /usr/bin/git-apple: Operation not permitted

4 Answers 4

11

sudo rm -rf /usr/bin/git wont work for El Capitan due to SIP restriction

simple solution is create alias

alias git='/usr/local/bin/git'
2
2

Use the below only if you want to remove the default GIT. You can still use package managers like homebrew and macports to install an alternative GIT.


The /usr/bin directory is restricted by SIP. You first need to temporarily disable it by booting to recovery, starting Terminal, and executing csrutil disable (then csrutil enable to re-enable`).

Once you have SIP disabled, you can remove git from /usr/bin.

See Also:


Note: You can check for SIP restrictions with the -Ol flags with ls. If it isn't restricted, you will see a hyphen, and if it is, you will see restricted.

2
  • 2
    While this may be a way to remove it, the OP should use a package manager such as homebrew to install a newer version instead. Aug 3, 2016 at 22:27
  • In defense of the OP, installing a newer version isn't effective unless you change your PATH (so that /usr/local/bin precedes /usr/bin) or create a git alias as suggested by @elliot-yap.
    – John
    Apr 16, 2020 at 13:47
1

I am generally not experienced enough to risk messing with system libraries (or anything that comes pre-installed with macOS). For this reason, I leave this answer for anyone else that may be in a similar situation.

My rule of thumb is that when something is in /usr that's a system resource and, generally speaking, I really shouldn't touch it (unless I really know what I'm doing, which I don't).

1

Please just install the Homebrew version of Git that is updated regularly.

Disabling SIP — and removing Git — can be done but it is honestly a bad idea.

While technically possible to do — as John K’s answer states — by disabling SIP this is an incredibly short-sighted thing to do and might cause more headaches down the line. Especially when an OS update happens and the macOS version of git is reinstalled.

It is much better to just install an updated version of Git via Homebrew.

Just run this command, copied directly from the main Homebrew site, to install Homebrew if you don’t have it installed at all right now like this:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed just run this command to install an updated version of Git like this:

brew install git

As of right now (February 9, 2023), it will install Git version 2.39.1. Confirm it is the version of Git that will be used when you type git by typing which git. On my Intel-based 2020 MacBook Air running macOS 13.2 (Ventura) system it shows the path as /usr/local/bin/git; which is the location of Homebrew installed version of Git and the parent directory contains other Homebrew installed binaries as well.

3
  • DOes your mac have an Intel processor - that path is not correct for Apple Silicon macs
    – mmmmmm
    Feb 10, 2023 at 10:24
  • 1
    On ARM, Homebrew installs to /opt/homebrew. On all platforms, brew --prefix will show the installation path.
    – nohillside
    Feb 10, 2023 at 15:10
  • 1
    Having said that: With recent versions of macOS, /usr/bin/git can't be replaced by the user anymore, so it's not just a bad idea...
    – nohillside
    Feb 10, 2023 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .