Installing and Configuring Git
Install Git on Windows, macOS or Linux, set your name and email, choose a default branch name and editor, and understand how Git configuration works.
On this page 11 sections
Introduction
Before you can track a project, Git needs to be installed and needs to know who you are — every commit you make is stamped with your name and email. This lesson takes about ten minutes, and you only ever do it once per computer.
- How to install Git on Windows, macOS and Linux.
- How to set the name and email that appear on your commits.
- How to choose a default branch name and a friendly editor.
- Where Git keeps its settings, and what the Windows line-ending warning means.
Installing Git
Open a terminal and run git --version first — Git may already be installed. If you see a version number, skip ahead. Otherwise, install it for your operating system:
| System | How to install |
|---|---|
| Windows | Download the installer from git-scm.com, or run: winget install --id Git.Git -e --source winget. It also installs Git Bash, a terminal that understands the commands in this course. |
| macOS | Run git --version in Terminal; macOS offers to install the Command Line Developer Tools, which include Git. With Homebrew: brew install git. |
| Ubuntu / Debian | sudo apt update && sudo apt install git |
| Fedora | sudo dnf install git |
Use Git Bash (installed with Git) or the terminal inside VS Code set to Git Bash. Every command in this course is shown the way it works there, on macOS Terminal and on Linux.
Introduce Yourself to Git
Tell Git your name and email. These are written into every commit you make, so use the email you will use for GitHub. The --global option means “use this for every repository on this computer”:
git config --global user.name "Priya Sharma"git config --global user.email "priya@example.com"These commands print nothing when they succeed — in the command line, no news is good news. Use your own name and email, of course. If you want to keep your email private on GitHub, you can use the special “noreply” address GitHub gives you in Settings → Emails.
Default Branch and Editor
When you create a repository, Git creates a first branch for you. Older versions of Git call it master; GitHub and most teams now use main. Set main as your default so your local repositories match GitHub:
git config --global init.defaultBranch mainSome Git commands open a text editor — for example, when you write a longer commit message or finish a merge. If you do not choose one, Git usually opens Vim, which confuses many beginners (to save and quit Vim, press Esc, type :wq and press Enter). If you use VS Code, set it as Git’s editor instead. The --wait flag tells Git to wait until you close the file:
git config --global core.editor "code --wait"Finally, tell Git how git pull should combine your work with a teammate’s when both of you have new commits. Recent versions of Git refuse to guess and stop with an error until you choose. Merging is the simplest choice for beginners (lesson 10 shows when it matters):
git config --global pull.rebase falseChecking Your Settings
List your global settings to check everything was saved:
git config --global --listClick Run to see what this code prints.
You can also ask for a single value. Notice that this command does not use --global — it shows the value Git will actually use in the current folder:
git config user.nameClick Run to see what this code prints.
You set up Git on a new laptop, but your commits on GitHub show up with an unknown grey avatar instead of your profile. Which command fixes it for future commits?
You just got a new laptop. Put the Git setup steps in order.
- Install Git and check it with git --version
- Check everything with git config --global --list
- Set init.defaultBranch, core.editor and pull.rebase
- Set user.name and user.email with --global
Configuration Levels
Git reads settings from three places, and the more specific one wins:
| Level | Option | Applies to | Stored in |
|---|---|---|---|
| System | --system | Every user on the computer | Git’s installation folder |
| Global | --global | All your repositories | ~/.gitconfig in your home folder |
| Local | --local (the default) | One repository only | .git/config inside that repository |
Local settings are useful when one project needs something different — for example, using your work email only in work repositories. Run git config user.email "you@company.com" inside that repository, without --global. The global file is plain text; here is what the commands above produced:
cat ~/.gitconfigClick Run to see what this code prints.
Line Endings on Windows
Windows ends lines of text with two invisible characters (CRLF), while macOS and Linux use one (LF). The Git for Windows installer handles this for you by default: it stores LF in the repository and gives you CRLF in your working files. Because of that, you may see a message like this when you add files:
warning: in the working copy of 'index.html', LF will be replaced by CRLF the next time Git touches itThis is a harmless notice, not an error — your files are fine and your commit still works. The outputs in this course are shown without it, exactly as they appear on macOS and Linux.
Common Mistakes
- Forgetting the quotes around a name with a space: user.name Priya Sharma sets the name to just “Priya”.
- Using an email that is not on your GitHub account, so commits are not linked to your profile.
- Typing --global inside a work project when you meant to set something for that project only.
- Panicking when Vim opens — press Esc, type :wq and press Enter, then set core.editor to an editor you know.
Frequently Asked Questions
Yes — run the same git config command again with the new value. It affects new commits only; existing commits keep the name and email they were made with.
No. Git works entirely on your computer. You will create a GitHub account in lesson 10, when you start sharing code.
Graphical clients are fine for viewing history, but learn the commands first. Every error message, tutorial and server uses them, and they make any graphical tool easy to understand.
Use the same method you installed with: re-run the Windows installer or winget upgrade Git.Git, brew upgrade git on macOS, or your Linux package manager.
Key Takeaways
- Check for Git with git --version, and install it from git-scm.com or your package manager.
- Set user.name and user.email globally — they are stamped on every commit.
- Set init.defaultBranch to main, choose an editor you are comfortable with, and set pull.rebase to false.
- Settings live at system, global (~/.gitconfig) and local (.git/config) levels; the most specific wins.
- The Windows “LF will be replaced by CRLF” message is a harmless notice.
Summary
Git is installed and knows who you are. In the next lesson you will create your first repository — a small portfolio website — and make your first commits, watching exactly what Git reports at every step.