burger
burger

Reputation: 5883

Homebrew update fail: "Please, commit your changes or stash them before you can merge"

I am running:

brew update

And I get an error:

error: Your local changes to the following files would be overwritten by merge:
    samtools.rb
Please, commit your changes or stash them before you can merge.
Aborting

It turns out this is a well known error. In fact, it's mentioned on the Homebrew wiki:

After running brew update, you receive a git error warning about untracked files or local changes that would be overwritten by a checkout or merge, followed by a list of files inside your Homebrew installation.

This is caused by an old bug in in the update code that has long since been fixed. However, the nature of the bug requires that you do the following:

cd $(brew --repository)
git reset --hard FETCH_HEAD

If brew doctor still complains about uncommitted modifications, also run this command:

cd $(brew --repository)/Library
git clean -fd

I followed those instructions and am still seeing the same error. What is wrong?

Upvotes: 72

Views: 40861

Answers (5)

Peiman Farajnezhad
Peiman Farajnezhad

Reputation: 39

I had the same issue and was able to resolve it by reinstalling xpipe using the following command:

brew reinstall xpipe

Upvotes: 0

Fabien
Fabien

Reputation: 787

To identify the faulty repository, you can execute the following command:

brew update --verbose

This will display what's happening under the hood. From there, you can navigate to the problematic repository:


cd /usr/local/problematic-repository

# See the list of changed files
git status

# Stash or checkout the changes
git stash

# Alternatively, checkout the specific file
git checkout my-file.rb

# take another chance with 
brew update

Upvotes: 0

michael
michael

Reputation: 21

I had this problem after manually correcting a URL in the numpy formula. I was able to correct this later by:

cd /usr/local/Library/Taps/homebrew/homebrew-python
git checkout -- numpy.rb
brew update

Upvotes: 2

javabrain
javabrain

Reputation: 383

This fixed it for me:

https://stackoverflow.com/a/20138806

cd `brew --prefix`
git fetch origin
git reset --hard origin/master

Upvotes: 36

burger
burger

Reputation: 5883

I was able to resolve the issue myself.

What tipped me off is running "git status" did not show that file.

Instead of using the common solution:

cd $(brew --repository)
git reset --hard FETCH_HEAD

I had to do:

cd [directory of the file in question]
git reset --hard FETCH_HEAD

That resolved the problem.

Upvotes: 109

Related Questions