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:
| Level | Applies to | Stored in | Flag |
|---|---|---|---|
| System | Every user on the computer | /etc/gitconfig | --system |
| Global | One user, every project | ~/.gitconfig | --global |
| Local | One 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
git config --global user.name "Nithin"This name appears on every commit.
2.Set an email
git config --global user.email "your-email@example.com"3.Name the default branch main
git config --global init.defaultBranch mainEvery 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
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
git config --global --listuser.name=Nithin
user.email=your-email@example.com
init.defaultbranch=main
core.editor=code --waitgit 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:
[user]
name = Nithin
email = your-email@example.com
[init]
defaultBranch = main
[core]
editor = code --waitOne more useful setting
git config --global pull.rebase falseThis tells git pull to combine changes with a merge, so it doesn't stop to ask how.