Skip to content

Instantly share code, notes, and snippets.

@ChrisTollefson
Last active February 21, 2024 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisTollefson/ab9c0a5d1dd4dd615217345c6936a307 to your computer and use it in GitHub Desktop.
Save ChrisTollefson/ab9c0a5d1dd4dd615217345c6936a307 to your computer and use it in GitHub Desktop.
Git Installation and Configuration

Git Installation and Configuration

Installation

macOS High Sierra

Version:

→ About This Mac → Overview → macOS High Sierra
Version 10.13.6


Option 1: Xcode

Version:

Xcode → About Xcode → Xcode
Version 10.0 (10A255)

Git Installation:
  • Use the Mac App Store app to install Xcode.
  • After installing Xcode, run it at least once to install additional components, which include Git.
  • Note: Apple's bundled version of Git is typically a few versions behind the current version of Git.

Option 2: Command Line Tools for Xcode

Version:

pkgutil --verbose --pkg-info=com.apple.pkg.CLTools_Executables
version: 10.0.0.0.1.1535735448

Git Installation:
  • Install Command Line Tools for Xcode, which includes Git: xcode-select --install
  • Use the Mac App Store app to update Command Line Tools for Xcode.
  • Note: Apple's bundled version of Git is typically a few versions behind the current version of Git.

Option 3: Homebrew

Version:

brew --version
Homebrew 1.7.5
Homebrew/homebrew-core (git revision 4f53; last commit 2018-09-18)

  • Website: https://brew.sh/
  • Install Homebrew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Installing Homebrew also installs Command Line Tools for Xcode.
  • Use the Mac App Store app to update Command Line Tools for Xcode.
  • Update Homebrew itself: brew update
  • Upgrade Homebrew apps: brew upgrade
Git Installation:
  • Install Git: brew install git
  • After installing Git, quit the Terminal application before using it.
  • Note: The Homebrew Git package will typically be more up-to-date than the version of Git that is bundled with Command Line Tools for Xcode.

Option 4: Git Installer

Git Binary Paths

Command
which git         
git --version                     
xcrun --find git                                      
xcrun --run git --version         
XcodeNote 1 /usr/bin/git git version 2.17.1 (Apple Git-112) /Applications/Xcode.app/Contents/Developer/usr/bin/git git version 2.17.1 (Apple Git-112)
Command Line ToolsNote 1 /usr/bin/git git version 2.17.1 (Apple Git-112) /Library/Developer/CommandLineTools/usr/bin/git git version 2.17.1 (Apple Git-112)
HomebrewNote 2 /usr/local/bin/git git version 2.19.0 /Library/Developer/CommandLineTools/usr/bin/git git version 2.17.1 (Apple Git-112)
Git Installer

Note 1: For Xcode and Command Line Tools for Xcode, /usr/bin/git is a stub that runs the actual ./usr/bin/git program contained within the Xcode application package or within the Command Line Tools for Xcode, according to the currently-active Xcode developer directory:

Command
xcode-select --print-path                 
Xcode /Applications/Xcode.app/Contents/Developer
Command Line Tools /Library/Developer/CommandLineTools
HomebrewNote 2 /Library/Developer/CommandLineTools

Note 2: Homebrew also installs Command Line Tools for Xcode, which itself installs an older version of Git that is invoked from /usr/bin/git. However, Homebrew installs its version of Git to /usr/local/bin/git, which, by default, occurs earlier in the search path; therefore the git command by itself without a path will invoke Homebrew's Git.

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Configuration

git config --global user.name "Your Name"
git config --global user.email "your.address@your.domain.tld"

Git Configuration File Paths

The file paths mentioned below are generalizations based on my own observations of clean installs on a freshly installed operationg system. For more specific details, refer to the official documentation: https://git-scm.com/docs/git-config.

Note: A more-specific setting will override a more-general setting. Specifically:

  • A --local setting will override a --global, --system, "core" and/or "program default" setting.
  • A --global setting will override a --system, "core" and/or "program default" setting, but not a --local setting.
  • A --system setting will override a "core" and/or "program default" setting, but not a --local or --global setting.
  • A "core" setting will override a "program default" setting, but not a --local, --global or --system setting.

0. Git program default settings

In the absence of a more-specific configuration setting in one of the locations below, Git will use it's own built-in program defaults.

There is currently no command to display those built-in program default settings, because the git config command only operates on the settings specified in the files below, and has no knowledge of Git's built-in settings.

Examine the Git source code (https://github.com/git/git) to determine what built-in settings the program uses by default.

1. "Core" configuration (read-only by default)

A setting applies to all repositories for all users, and overrides a default program setting, unless overridden by a more-specific setting below.

Command
git config --list --show-origin                                        
xcrun --run git config --list --show-origin                            
Xcode /Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig /Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig
Command Line Tools /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig
Homebrew N/A /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig
Git Installer

Note: There isn't actually a command to display or change these "core" settings explicitly; but the git config command without the --system, --global or --local options will --list and --show-origin of any such settings that are not overridden by more specific settings below. In this way, this command might reveal the location of such a "core" settings file.

2. "System" (computer-wide) configuration

A setting applies to all repositories for all users, and overrides a more-general setting above, unless overridden by a more-specific setting below.

Command
git config --system --list --show-origin
xcrun --run git config --system --list --show-origin
Xcode /etc/gitconfig /etc/gitconfig
Command Line Tools /etc/gitconfig /etc/gitconfig
Homebrew /usr/local/etc/gitconfig /etc/gitconfig
Git Installer

3. "Global" (user-specific) configuration

A setting applies to all repositories for the current user only, and overrides a more-general setting above, unless overridden by a more-specific setting below.

Command
git config --global --list --show-origin
xcrun --run git config --global --list --show-origin
Xcode ~/.gitconfig ~/.gitconfig
Command Line Tools ~/.gitconfig ~/.gitconfig
Homebrew ~/.gitconfig ~/.gitconfig
Git Installer

4. "Local" (repository-specific) configuration

A setting applies only to the current repository for all users, and overrides a more-general setting above.

Command
git config --local --list --show-origin
xcrun --run git config --local --list --show-origin
Xcode /path/to/repository/.git/config /path/to/repository/.git/config
Command Line Tools /path/to/repository/.git/config /path/to/repository/.git/config
Homebrew /path/to/repository/.git/config /path/to/repository/.git/config
Git Installer

See Also

Installing Git: https://git-scm.com/book/en/Getting-Started-Installing-Git

Configuration Documentation: https://git-scm.com/docs/git-config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment