Git Install and Config

Before using Git you need to install it and configure a few settings. The most important are your name and email, which Git attaches to every commit you make.

Installing Git

  • Windows: download Git for Windows from git-scm.com. It includes Git Bash, a terminal with common Unix commands.
  • macOS: run git --version; macOS offers to install the Xcode Command Line Tools, or use Homebrew: brew install git.
  • Linux (Debian/Ubuntu): sudo apt install git. Fedora: sudo dnf install git.

Check the Installation

git --version
git version 2.47.0

Set Your Name and Email

The --global flag saves the setting for every repository on your computer. Use the same email as your GitHub or GitLab account so commits link to your profile.

git config --global user.name "Naeem Amin"
git config --global user.email "you@example.com"
(no output means success)

Recommended Settings

defaultBranch makes new repositories start on main. core.editor chooses the editor Git opens for commit messages (here VS Code). core.autocrlf handles the different line endings used by Windows and Unix.

git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global pull.rebase false
git config --global core.autocrlf true      # Windows only
git config --global core.autocrlf input     # macOS/Linux
(no output)

Viewing Your Configuration

git config --list --show-origin
git config user.name
file:C:/Users/naeem/.gitconfig  user.name=Naeem Amin
file:C:/Users/naeem/.gitconfig  user.email=you@example.com
file:C:/Users/naeem/.gitconfig  init.defaultbranch=main
Naeem Amin

Configuration Levels

  • --system: every user on the machine
  • --global: your user account (~/.gitconfig)
  • --local: one repository only (.git/config) — the default when you omit a flag
  • More specific levels override general ones, so you can use a work email in one repo.

Handy Aliases

Aliases create shortcuts for long commands. For example git config --global alias.lg "log --oneline --graph --all" lets you type git lg to see a compact history graph.

Frequently asked questions

How do I change my Git username and email?

Run git config --global user.name "New Name" and git config --global user.email "new@email.com". This affects future commits, not existing ones.

How do I set main as the default branch in Git?

Run git config --global init.defaultBranch main. New repositories created with git init will then start on main instead of master.

Where is the global Git config file stored?

In your home folder as .gitconfig, for example C:\Users\you\.gitconfig on Windows or ~/.gitconfig on macOS and Linux.