Error while trying to update brew package manager - macos

I tried to update brew:
sudo brew update
But I got this error:
error: Your local changes to the following files would be overwritten by merge:
Listing a lot of files
Error: Failed while executing git pull http://github.com/mxcl/homebrew.git master
Any idea what is going wrong?

There was a bug in Homebrew that was fixed just a few days ago. To fix the bug you can run git reset --hard FETCH_HEAD inside your Homebrew installation. Since that won't fix files that are already seen as modified you can also run git checkout Library to replace your checkout with the latest files. (That wipes all edits so take appropriate measures with any you made.)

The accepted answer is correct but incomplete. If you are getting the error of
error: The following untracked working tree files would be overwritten by merge:
Then go to your terminal and run these commands
cd /usr/local
Then
git reset --hard FETCH_HEAD
Then
git checkout Library
That should get everything in order. Then run
brew update

Let me add: cd /usr/local/git
and then run git reset --hard FETCH_HEAD

go to your terminal and run these commands
cd /usr/local
sudo git reset --hard FETCH_HEAD
sudo git checkout Library

For those of you using OS X El Capitan, your problem may be System Integrity Protection.
If /usr/local exists already, run the following in Terminal:
sudo chown -R $(whoami):admin /usr/local
If /usr/local does not exist:
First, try to create /usr/local the normal way:
sudo mkdir /usr/local && sudo chflags norestricted /usr/local && sudo chown -R $(whoami):admin /usr/local
If you see permission issues instead try:
Reboot into Recovery mode (Hold Cmd+R on boot) & access the Terminal.
In that terminal run: csrutil disable
Reboot back into OS X
Open your Terminal application and execute the line from just above
Reboot back into Recovery Mode & access the Terminal again.
In that terminal execute: csrutil enable
Reboot back into OS X & you'll be able to write to /usr/local & install Homebrew.

Out of no reason (or at least no one I'd understand) the repository in /usr/local (which is the brew install!) lost its remote repository. So, neither a git reset nor a git pull and for sure no brew update would work.
How do you know that happened? Check /usr/local/.git/config whether there are some lines like the following:
[remote "origin"]
url = http://github.com/mxcl/homebrew.git
fetch = +refs/heads/*:refs/remotes/origin/*
If not do as follows:
cd /usr/local
git remote add origin http://github.com/mxcl/homebrew.git
git pull origin master

Related

'git init -b <branch name>' command in terminal is throwing an 'unknown switch' error

I am trying to add an existing project to GitHub using the command line. I am in the relevant working directory in the terminal and am trying to use the git init -b main command.
Initially, I was getting an error relating to xcode:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
I tried xcode-select --install but the software was unavailable from the update server, so I downloaded 'Command Line Tools for Xcode 12' from https://developer.apple.com/download/more/.
Now on entering git init -b main I am getting the following:
error: unknown switch `b'
usage: git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [<directory>]
--template <template-directory>
directory from which templates will be used
--bare create a bare repository
--shared[=<permissions>]
specify that the git repository is to be shared amongst several users
-q, --quiet be quiet
--separate-git-dir <gitdir>
separate git dir from working tree
I am running git version: 2.24.3 (Apple Git-128)
Any help much appreciated!
The -b flag is only available in version 2.28 or later, you need to upgrade your Git.
On debian-based Linux systems such as Ubuntu, do the following:
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update
sudo apt install git -y
git 2.24 doesn't have option -b/--initial-branch. It was added in git 2.28. You need to upgrade to use the option.
Or, as #matt said, create a repo and then rename the branch:
git init repo
cd repo
git branch -m master slave
prior to git v2.28
git init # ①
git symbolic-ref HEAD refs/heads/main # ②
① After git init, the branch master does not actually exist. Branches get created only when they have at least one commit.
② This updates .git/HEAD to contain ref: refs/heads/main instead of ref: refs/heads/master. Alternatively, git checkout -b main.
git v2.28+
As #phd said, the -b/--initial-branch option was added in git v2.28. git 2.28 also introduces a config option to specify your preferred default branch:
git config --global init.defaultBranch main
Learn more about the new init.defaultBranch setting in GitHub's blog post.
In case you need to install the latest git version (in Ubuntu)
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
Ref: https://gist.github.com/YuMS/6d7639480b17523f6f01490f285da509
This is happening due to the unavailability of a tool called Xcode Select, running xcode-select --install in your terminal fixes these issues with Git not working.

How to get back Homebrew to previous state?

I deleted some of .rb files(cassandra.rb,cassandra#2.1.rb and cassandra#2.2.rb) from folder /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/ from mac system.I want back those .rb files.I thought brew upgrade will give me back those deleted .rb files back.But they are still missing. Those .rb files are important for me to install packages.
brew install cassandra gives
Updating Homebrew...
Error: No available formula with the name "cassandra"
==> Searching for a previously deleted formula...
cassandra was deleted from homebrew/core in commit d20fe73:
cassandra: update 3.10_1 bottle.
To show the formula before removal run:
git -C "$(brew --repo homebrew/core)" show d20fe73^:Formula/cassandra.rb
If you still use this formula consider creating your own tap:
http://docs.brew.sh/How-to-Create-and-Maintain-a-Tap.html
Please I need solution "how to get back these .rb files?" or "any other alternative way to install cassandra".
Install directly from GitHub as mentioned here -
How to restore brew formula after I rm it
brew install https://github.com/Homebrew/homebrew-core/tree/master/Formula/cassandra.rb
Try this command to bring back all of deleted files.
Note: This command will revert all change in $(brew --repo homebrew/core)
cd $(brew --repo homebrew/core) && git reset --hard origin/master
Homebrew uses git internally, so use git commands to repair some problem.

Updated Git but still showing old version

I downloaded and installed Git 1.8.4.2 from this link: http://git-scm.com/downloads. However, when I run git --version from the Terminal I get:
[~/workspace/ruby]: git --version
git version 1.7.4.4
I've tried restarting the terminal and my computer. I then tried using the info at https://code.google.com/p/git-osx-installer/wiki/Uninstall. I did the following in the terminal from within /usr:
sudo rm -rf /usr/local/git
sudo rm /etc/paths.d/git
sudo rm /etc/manpaths.d/git
I then ran the new git .dmg file again but am still getting 1.7.4.4 when I run git --version. I suppose there's something going on here with the Mac filesystem that I don't understand. Any help would be greatly appreciated!
Run the command:
which git
You'll probably see /usr/bin/git -- the Apple supplied version. This will be because /usr/bin appears in your PATH environment variable before /usr/local/git/bin. You can verify this by running the command:
echo $PATH
If that is the case then run this command:
export PATH=/usr/local/git/bin:$PATH
and then try git --version again. You should now get 1.8.4.2. This hasn't fixed it permanently yet though. You'll need to add the export PATH=... line to your ~/.bashrc so that it gets set for every shell.

Git hanging after installing osx credential helper

I'm having the same problem as this thread: Git hangs indefinitely - broke with osx credential helper I think
Basically -- had been running git without problems, then installed the credential-osxkeychain and git began hanging indefinitely after any command. e.g., running git init results in a hanging prompt and any input creates an error: bad input
I tried following the advice to delete git from usr/bin/git but now it doesn't recognize anything. I tried reinstalling git but now it doesn't seem to recognize it.
I ran which git and it returns: /usr/local/git/bin/git
I'm somewhat new at this and don't have the balls to just start running sudo commands and moving things around in the /usr/bin directory.
Any ideas what I can do to fix this?
I had the same problem and fixed it thusly:
uninstall git via the uninstall.sh that comes with the install
reinstall git via the installer
run which git and cd to the folder containing git (eg. cd /usr/local/git/bin/)
run curl -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
run chmod u+x git-credential-osxkeychain
run git config --global credential.helper osxkeychain
Fixed.
Still not totally sure what I actually did to fix this problem, but resetting the terminal ended up getting it to work.
I had the same problem.
I didnt have git 1.7.10 or later installed. Messed everything up.
To fix, I had to delete git and install a newer version.
I used homebrew to install, after deleting.
is working again.
To fix this I reinstalled git from http://git-scm.com/download/mac
and then added /usr/local/git/bin to the top of the file /etc/paths

Trying to install git on OSX: cannont exec 'git-credential-osxkeychain': Permission denied`

I'm attempting to install Git on my new MBP and am following the documentation # https://help.github.com/articles/set-up-git.
I seem to have hit a snag at the point where it says : If you do not have the helper, you can download it and copy it to /usr/local/bin
I navigated to /usr/local/bin in terminal and did a sudo wget [link to osxkeychain]. When I try to do a git config --global credential.helper osxkeychain I get a fatal: cannont exec 'git-credential-osxkeychain': Permission denied.
What did I do wrong?
Thanks!
Tre
Download the git-credential-osxkeychain file to your desktop(!).
Open the Terminal application.
Type in the following:
sudo cp ~/Desktop/git-credential-osxkeychain /usr/local/bin/git-credential-osxkeychain
sudo chmod 755 /usr/local/bin/git-credential-osxkeychain
sudo git config --global credential.helper osxkeychain
Test it with:
sudo git credential-osxkeychain
See the sudo prefix? It seems to be required for the credential stuff... It should now output Usage: git credential-osxkeychain <get|store|erase>
Make the downloaded file executable:
chmod 755 git-credential-osxkeychain
Homebrew's git package sets this up; just:
brew install git
and you're away.
Tried sudo?
/usr/bin is protected. Or you could try downloading git executables somewhere on your laptop and add that location to your PATH.
One of the common mistakes made by people starting on git is that they have the wrong executable for the operating system.
Please make sure that when you go to git help setup page you click on the right link
for example the following link has MAC | WINDOWS | LINUX | ALL options in the top of the page which is small enough to be ignored by many.
https://help.github.com/articles/set-up-git
This has happened to many of my team member to install osx for ubuntu and end up getting the error mentioned above

Resources