Before you can configure Git, you need to install it on your system. The method varies depending on your operating system.
# First, update your package list
sudo apt update
# Then, install Git
sudo apt install gitThe easiest way to install Git on a Mac is by using the Homebrew package manager.
# Install Git using Homebrew
brew install gitNote: If you don't have Homebrew, you can also get Git by installing the Xcode Command Line Tools from Apple.
For Windows, the most straightforward method is to download the official installer from the Git website. This package includes Git Bash, a terminal that allows you to run Git commands in a Unix-like environment.
- Download the installer from git-scm.com
This is the first step you should take after installing Git. Your name and email are attached to every single commit you make, so this identifies you as the author.
Before setting anything, you can check if a name and email are already configured on your machine.
# Check the currently set user name
git config user.name
# Check the currently set user email
git config user.email
# Alternative: List all settings and filter for "name"
# git config --list | grep nameThese commands set your identity for all Git repositories on your computer (that's what the --global flag does).
Note: You should use the same email address that you use for your GitHub, GitLab, or other Git hosting account.
# Sets your user name for all repositories
git config set --global user.name "github_username_here"
# Sets your email for all repositories
git config set --global user.email "email@example.com"Git stores these global settings in a file named .gitconfig located in your user's home directory (~/). You can view the raw contents of this file to confirm your settings were saved.
# 'cat' is a command to display the contents of a file
cat ~/.gitconfig