Git is one of the most popular version control systems. It comes pre-installed on macOS. However, Apple's bundled version of Git is not as well-maintained as the official Git repo.
-
Make sure you have installed Homebrew on your system - if not, read the Homebrew guide;
which brew
-
Open terminal and run the following command:
brew install git
-
Verify git has been installed.
git --version
- Set Git editor;
git config --global core.editor "nano"- Set Git default push behaviour;
git config --global push.default simple- Set Git user;
git config --global user.name "Your Name"
git config --global user.email you@example.comIgnore this section if you are NOT a bash user.
-
Create configuration files;
touch ~/.bash_profile touch ~/.git-completion.bash touch ~/.git-prompt.sh
-
Populate
.git-completion.bashwith https://github.com/git/git/blob/master/contrib/completion/git-completion.bash; -
Populate
.git-prompt.shwith https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh; -
Update permissions of
.git-completion.bashand.git-prompt.sh;chmod 755 ~/.git-completion.bash chmod 755 ~/.git-prompt.sh
-
Populate
.bash_profile, as follows:#!/bin/bash export PATH="/usr/local/bin:$PATH" source ~/.git-completion.bash source ~/.git-prompt.sh MAGENTA="\[\033[0;35m\]" YELLOW="\[\033[0;33m\]" BLUE="\[\033[34m\]" LIGHT_GRAY="\[\033[0;37m\]" CYAN="\[\033[0;36m\]" GREEN="\[\033[0;32m\]" GIT_PS1_SHOWDIRTYSTATE=true export LS_OPTIONS='--color=auto' export CLICOLOR='Yes' export LSCOLORS=gxfxbEaEBxxEhEhBaDaCaD export PS1=$LIGHT_GRAY"\u@\h"'$( if [[ $(__git_ps1) =~ \*\)$ ]] # a file has been modified but not added then echo "'$YELLOW'"$(__git_ps1 " (%s)") elif [[ $(__git_ps1) =~ \+\)$ ]] # a file has been added, but not commited then echo "'$MAGENTA'"$(__git_ps1 " (%s)") # the state is clean, changes are commited else echo "'$CYAN'"$(__git_ps1 " (%s)") fi)'$BLUE" \w"$GREEN": " alias ll='ls -lah' alias gg='git status -s'
Please note: You need to restart your terminal for the settings to take effect.