Install and Configure Git
Introduction
Git is a version control system for tracking code changes and is an integral part of our CMS at Travel Tripper. You can learn more about it on the Wiki or the official docs.
Prerequisites
If you don’t already have a Github account, you will need to create one. Once you have a Github username, send it to your lead developer so you can be added to the Travel Tripper Org.
Windows
How you install git on your Windows system depends on how you’ve setup your local build tools.
If you’re using the Linux Subsystem and using git in bash, you can find the instructions here: Install Git in Linux Subsystem.
If you’re using local build tools (not the Linux Subsystem), you can find instructions here: Install Git in Windows.
MacOS
You will need to have Homebrew installed before beginning.
brew install git
Ubuntu
sudo apt update && sudo apt install git
Linux Mint
The Linux Mint repos are often well behind the current build. It is best if you install git from a PPA so you have the latest version.
sudo add-apt-repository -y ppa:git-core/ppa
Once the PPA is added you can install the same as Ubuntu.
sudo apt update && sudo apt install git
Configure Git
Now that you have Git on your system, you’ll want to do a few things to customize your Git environment.
Git comes with a tool called git config
that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three places:
/etc/gitconfig
file: Contains values applied to every user on the system and all their repositories. If you pass the option--system
togit config
, it reads and writes from this file specifically. (Because this is a system configuration file, you would need administrative or superuser privilege to make changes to it.)~/.gitconfig
or~/.config/git/config
file: Values specific personally to you, the user. You can make Git read and write to this file specifically by passing the--global
option.config
file in the Git directory (that is,.git/config
) of whatever repository you’re currently using: Specific to that single repository.
Each level overrides values in the previous level, so values in .git/config
trump those in /etc/gitconfig
.
On Windows systems, Git looks for the .gitconfig
file in the $HOME
directory (C:\Users\$USER
on most systems). It still looks for /etc/gitconfig
, although it’s relative to the MSys root, which is wherever you installed Git on your system. If you are using version 2 or later, there is also a system-level config file in C:\ProgramData\Git\config
. This config file can only be changed by git config -f <file>
as an admin.
Your Identity
At a minimum set your name and email address (this should probably be your GitHub email address).
git config --global user.name "John Brown"
git config --global user.email johnbrown@traveltripper.com
You’ll probably want to set default push status, set the UI to show you colors, and add your global .gitignore as well.
git config --global push.default simple
git config --global color.ui true
git config --global core.excludesfile /home/<linux-user-name>/.gitignore
Your Editor
This is optional, but you can configure the default text editor that will be used when Git needs you to type a message. If not configured, Git uses your system’s default editor.
If you want to use a different text editor, such as Nano, you can do the following:
git config --global core.editor nano
If you set this up with vim or emacs, you’re on your own—Stackoverflow is your friend.
If you are on Windows and you want to use a different text editor check the official docs for instructions.
Checking Your Settings
If you want to check your configuration, you can use git config --list
.
Example .gitconfig
You can also set all these by editing your ~/.gitconfig
file. To give you an example, here is what Brad’s looks like:
[user]
name = Brad West
email = brad@bradonomics.com
[push]
default = simple
[color]
ui = true
[core]
excludesfile = /home/brad/.gitignore
editor = nano