Install & Configure Git

Git · Lesson 2 of 28 7 min read Updated

Before you can track any project, you need Git on your computer and a few one-time settings: your name and email (which go into every commit), the name of the first branch, and the editor Git should open. This takes about ten minutes and you only do it once per computer.

This lesson shows each step on Windows, macOS and Linux, and explains where Git keeps its settings so you can check or change them later.

Installing Git

Windows. Download the installer from the official site, git-scm.com, and run it. The package is called Git for Windows. It installs git itself, Git Bash (a terminal that understands Linux-style commands such as ls and cat), and Git Credential Manager, which stores your GitHub login safely. The installer asks many questions; the defaults are fine for beginners. When it asks about the default branch name, choose to override it and type main. If you prefer the command line, Windows' package manager can install it too:

PowerShell
winget install --id Git.Git -e --source winget

macOS. Open Terminal and type git --version. If Git is missing, macOS offers to install the Xcode Command Line Tools, which include Git. If you use Homebrew, brew install git gives you a newer version.

Linux. Use your distribution's package manager. On Ubuntu or Debian:

Terminal
sudo apt update
sudo apt install git

On Fedora the command is sudo dnf install git. Distribution packages are sometimes a few versions behind the newest release; that is fine for learning.

Check that Git works

Open a new terminal (on Windows, Git Bash or PowerShell both work) and ask for the version:

Terminal
git --version
Output
git version 2.56.0.windows.2

On macOS and Linux you will see something like git version 2.56.0 without the Windows part. If you get "command not found" or "'git' is not recognized", close and reopen the terminal so it picks up the new program; if that fails, reinstall and make sure the option to add Git to your PATH is selected.

Tell Git who you are

Every commit records an author name and email. Set them once for your user account with --global. Git 2.46 added clear subcommands to git config (set, get, list, unset), so modern Git reads almost like English:

Terminal
git config set --global user.name "Priya Sharma"
git config set --global user.email "priya@example.com"
git config get user.name
git config get user.email
Output
Priya Sharma
priya@example.com

Use the same email you will use on GitHub, so GitHub can link your commits to your profile. If you do not want your real email in public history, GitHub gives every account a private "noreply" address in its email settings; you can use that instead.

Choose your default branch and editor

When you create a new repository, Git creates a first branch. Older versions always called it master; GitHub and most teams now use main. Git 2.56 still uses master unless you say otherwise, and prints a long hint when you run git init:

Output
hint: Using 'master' as the name for the initial branch. This default branch name
hint: will change to "main" in Git 3.0. To configure the initial branch name
hint: to use in all of your new repositories, which will suppress this warning,
hint: call:
hint:
hint: 	git config --global init.defaultBranch <name>

Set it once and the hint disappears. While you are here, choose the editor Git opens when it needs you to write a longer message. This example uses Visual Studio Code; --wait tells Git to wait until you close the file:

Terminal
git config set --global init.defaultBranch main
git config set --global core.editor "code --wait"

If you prefer something simpler, nano works in any Linux or macOS terminal, and Notepad works on Windows ("notepad").

Where settings live

Git reads settings from three levels. A more specific level overrides a more general one:

LevelOptionFileApplies to
System--systemInside the Git installation folderEvery user on the computer
Global--global.gitconfig in your home folderAll your repositories
Local--local (the default).git/config inside one repositoryOnly that repository

To see every setting and the file it came from, use git config list --show-origin:

Terminal
git config list --show-origin
Output
file:C:/Users/priya/.gitconfig	user.name=Priya Sharma
file:C:/Users/priya/.gitconfig	user.email=priya@example.com
file:C:/Users/priya/.gitconfig	init.defaultbranch=main
file:C:/Users/priya/.gitconfig	core.editor=code --wait

On a real Windows machine you will also see lines from the system file that the installer created (for example core.autocrlf=true and credential.helper=manager). The global file itself is plain text, so you can open it in any editor:

Text
[user]
	name = Priya Sharma
	email = priya@example.com
[init]
	defaultBranch = main
[core]
	editor = code --wait

A local setting is useful when one project needs a different identity, such as your college email for a college project. Run this inside that repository, without --global: git config set user.email "priya.sharma@college.example.edu".

Line endings on Windows

Windows ends lines in text files with two characters (CRLF), while macOS and Linux use one (LF). The Git for Windows installer sets core.autocrlf=true by default, which converts to LF when you commit and back to CRLF when you check files out, so mixed teams do not see every line as changed. Leave this default alone unless your team says otherwise. You may see a warning such as "LF will be replaced by CRLF the next time Git touches it"; it is harmless.

Common mistakes

  • Forgetting the email setup. Git refuses to commit with "Please tell me who you are" until user.name and user.email are set. Run the two commands above.
  • A typo in the email. Commits made with the wrong email do not show on your GitHub profile. Fix the setting; future commits will use the new value.
  • Editor never closes. If core.editor is code without --wait, Git thinks you finished immediately and may abort the commit. Always add --wait for VS Code.
  • Setting things in the wrong level. Running git config set user.name ... without --global outside a repository fails, and inside one it only affects that repository.

Key points

  • Install Git from git-scm.com (Windows), the Command Line Tools or Homebrew (macOS), or your package manager (Linux).
  • git --version confirms the installation.
  • Set user.name and user.email once with git config set --global; every commit records them.
  • Set init.defaultBranch to main and choose an editor with core.editor.
  • Settings live at system, global and local levels; git config list --show-origin shows them all.

Exercise

Install Git on your computer and configure it: set your name, your email, main as the default branch and an editor you like. Then print the whole list of settings with their origin and find the line that shows your email.

Show solution
Terminal
git --version
git config set --global user.name "Ananya Iyer"
git config set --global user.email "ananya@example.com"
git config set --global init.defaultBranch main
git config set --global core.editor "code --wait"
git config list --show-origin

The email line looks like file:C:/Users/ananya/.gitconfig user.email=ananya@example.com. If your Git is older than 2.46, write git config --global user.name "Ananya Iyer" instead of git config set --global ....

Quick Quiz

1. Which command sets your name for every repository on your computer?

2. Where does Git store a setting made with --global?

3. Why should you add --wait when using VS Code as Git's editor?

4. What will the default branch name be for new repositories in Git 3.0?

Learn Git with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call