Git and GitHub · Part 1 · Git basics

Setting up Git properly

Why setup matters

Every commit records who made it. Git reads that from its settings instead of asking each time, so a name and email are set once and attached to every commit after that, like writing a name inside a new notebook.

Where Git keeps its settings

Settings live at three levels:

LevelApplies toStored inFlag
SystemEvery user on the computer/etc/gitconfig--system
GlobalOne user, every project~/.gitconfig--global
LocalOne project.git/config--local

The most specific level wins: a work project with its own local email uses that instead of the global one. Most settings are global, including every one below.

Setting up Git

1.Set a name

Terminal
git config --global user.name "Nithin"

This name appears on every commit.

2.Set an email

Terminal
git config --global user.email "your-email@example.com"

3.Name the default branch main

Terminal
git config --global init.defaultBranch main

Every new project starts with one branch. Older Git called it master; GitHub and most teams now use main, and this setting matches them.

4.Set an editor

Terminal
git config --global core.editor "code --wait"

Some commands open an editor, for example to write a long commit message. This makes it VS Code, and --wait makes Git wait until the file is closed. If code isn't found, run Shell Command: Install 'code' command in PATH from VS Code's command palette (Cmd + Shift + P).

5.Check the settings

Terminal
git config --global --list
Output
user.name=Nithin
user.email=your-email@example.com
init.defaultbranch=main
core.editor=code --wait

git config user.name checks a single value. All of these commands just write to a plain text file, ~/.gitconfig, which can also be edited by hand:

~/.gitconfig
[user]
    name = Nithin
    email = your-email@example.com
[init]
    defaultBranch = main
[core]
    editor = code --wait

One more useful setting

Terminal
git config --global pull.rebase false

This tells git pull to combine changes with a merge, so it doesn't stop to ask how.