Tag Archives: Homebrew

Global Homebrew PATH Prefix for macOS

Based on Homebrew’s FAQ you can set prefix in PATH for all GUI apps which is not enabled by default:

user$ sudo launchctl config user path "$(brew --prefix)/bin:${PATH}"
Configuration applied. You must reboot for changes to take effect.

According to this answer. The sudo launchctl config user path <...> command updates /private/var/db/com.apple.xpc.launchd/config/user.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

You can query launchd‘s current settings via:

launchctl getenv PATH

Related: You can also query the default PATH by executing:

sysctl user.cs_path

Test script with clear environment:

env -i git commit

Migrate Homebrew from Intel Macs to Apple Silicon Macs

Dump all your existing Homebrew packages:

brew bundle dump

If you’re using custom shell installed by Homebrew (ie. fish), change it back to bash temporarily:

chsh -s /bin/bash

You may also need to change this in System Preferences – Users & Groups (right click on your avatar and choose Advanced Options…)

Uninstall existing Homebrew (and all its packages):

curl -fsSL -o /tmp/uninstall.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
/bin/bash /tmp/uninstall.sh --path=/usr/local
Continue reading

Signing Git Commits without Entering Password Using `gpg-agent` and `pinentry-mac` on OS X

Install required packages via Homebrew:

$ brew install gpg gpg-agent pinentry-mac

Edit and add the following lines in ~/.gnupg/gpg-agent.conf:

pinentry-program /usr/local/bin/pinentry-mac

Edit and enable use-agent in ~/.gnupg/gpg.conf:


Then add the following line to your shell profile:

eval $(gpg-agent --daemon --sh)

更新 Homebrew 时出现 Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master 的解决方案


[email protected]:/Users/mom$ brew update
remote: Counting objects: 2482, done.
remote: Compressing objects: 100% (750/750), done.
remote: Total 2105 (delta 1543), reused 1822 (delta 1349)
Receiving objects: 100% (2105/2105), 329.33 KiB | 122 KiB/s, done.
Resolving deltas: 100% (1543/1543), completed with 295 local objects.
From https://github.com/mxcl/homebrew
   f884112..28f7e01  master     -> origin/master
error: The following untracked working tree files would be overwritten by merge:
Please move or remove them before you can merge.
Updating f884112..28f7e01
Error: Failed while executing git pull  origin refs/heads/master:refs/remotes/origin/master


cd `brew --prefix`

git clean -n # Does a dry run---shows what will get nuked without touching anything
git clean -f # This will destroy files