You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Before you can use Git you need to install it and tell it who you are. This lesson walks through installation on every major operating system and covers the essential configuration steps that apply to every project you will ever work on.
The easiest way to get Git on macOS is through Homebrew, the popular package manager:
brew install git
Alternatively, installing the Xcode Command Line Tools also installs Git:
xcode-select --install
After installation, verify it worked:
git --version
Download the official Git for Windows installer from git-scm.com. The installer includes Git Bash, a terminal emulator that gives you a Unix-like shell on Windows. During installation the defaults are sensible — leave them as-is unless you have a specific reason to change them.
On Debian and Ubuntu-based systems:
sudo apt update
sudo apt install git
On Fedora and Red Hat-based systems:
sudo dnf install git
Every Git commit records the author's name and email address. You must set these before making your first commit. Use the --global flag to apply the settings to every repository on your machine:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
These values are stored in a file called .gitconfig in your home directory.
Modern convention names the primary branch main instead of the older default master. Configure this globally so every new repository you create uses it:
git config --global init.defaultBranch main
When Git needs you to write a message (for example, during a merge), it opens a text editor. The default is often vi, which can be confusing for newcomers. Switch it to nano or VS Code:
# Use nano
git config --global core.editor nano
# Use VS Code
git config --global core.editor "code --wait"
To see all your current settings:
git config --list
To check a specific value:
git config user.name
On Windows, configure Git to handle line endings automatically so files are consistent across operating systems:
git config --global core.autocrlf true
On macOS and Linux:
git config --global core.autocrlf input
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.