Chapter 1.2☕ 15 min read

Setup & First Commit

Pehla commit hai woh pehla qadam — future wala tum thank karega.

01Set Your Identity — user.name & user.email

Before you make any commit, Git needs to know WHO you are. Every commit is stamped with an author name and email — this is non-negotiable.

Without identity, Git refuses to commit or uses generic system defaults — destroying accountability. When you look at history 6 months later, you need to know WHO made each change and WHY.

git config --global user.name "Your Name" and git config --global user.email "you@example.com" — set once, works for all repos on your machine.

The email MUST match your GitHub/GitLab email — otherwise your commits won't link to your profile. No green squares, no proof you wrote the code.

Config levels: --system (all users on machine), --global (your user), --local (current repo only). Priority: local > global > system.

# Set your identity — do this FIRST before any commit
git config --global user.name "Sai Kumar"
git config --global user.email "sai@devinhyderabad.com"

# Verify your settings
git config --list --global
# user.name=Sai Kumar
# user.email=sai@devinhyderabad.com

# CRITICAL: Email must match your GitHub email
# Wrong: git config --global user.email "personal@gmail.com"
# If your GitHub account uses "sai@company.com", use THAT email
# Otherwise your commits won't show on your GitHub profile

# Per-repo override (work vs personal)
cd work-project
git config --local user.email "sai@company.com"
The #1 mistake: using the wrong email. If your git config email doesn't match your GitHub email, your commits won't appear on your GitHub profile. No green contribution squares, no proof you wrote the code. Always verify with git config user.email inside each repo.
02Config Levels & Aliases

Git config has 3 levels: system, global, and local. Understanding these levels is crucial for managing different projects and teams.

--system applies to ALL users on the machine. Stored in /etc/gitconfig. Rarely used — usually set by system admins.

--global applies to YOUR user account. Stored in ~/.gitconfig. This is where 90% of your settings live.

--local applies to ONE repo only. Stored in .git/config inside the repo. Use this for per-repo overrides like work email.

Local overrides global, global overrides system. Most developers only use --global and --local.

Set your editor: git config --global core.editor "code --wait" (VS Code), or nano, vim, etc.

Useful aliases: git config --global alias.st status, alias.co checkout, alias.br branch, alias.lg "log --oneline --graph --all".

Default branch name: git config --global init.defaultBranch main — modern standard, not master.

# Set VS Code as default editor (waits until you close the file)
git config --global core.editor "code --wait"

# Set nano (simpler than vim for beginners)
git config --global core.editor "nano"

# Must-have aliases — save typing 100 times a day
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all"

# Now you can type:
git st    # instead of git status
git lg    # instead of git log --oneline --graph --all

# Set default branch to main (not master)
git config --global init.defaultBranch main

# See where a config value comes from
git config --show-origin user.name
# file:/home/sai/.gitconfig    Sai Kumar
03git init — Transforming a Folder

git init transforms an ordinary folder into a Git repository. It creates the .git/ directory — that is the ONLY thing it does.

Nothing changes in your files — but Git is now watching everything in this folder. Your files are completely untouched.

You only run git init ONCE per project. Running it again in an already-initialized repo is safe but pointless — Git detects the existing repo and reinitializes.

The first commit creates the main branch. Before the first commit, you are on an "orphan" branch with no history — git log returns nothing.

git init in the WRONG directory (like ~ or /) is a disaster — Git tracks everything recursively. Always cd into your project first.

# Create a new project
mkdir my-website && cd my-website

# Initialize Git
git init
# Initialized empty Git repository in /my-website/.git/

# What changed? Only one thing:
ls -la
# .git/   ← this hidden folder IS the repository now

# Verify Git is active
git status
# On branch main  (or master, depending on config)
# No commits yet
# nothing to commit

# WRONG — never do this:
cd ~
git init   # Now your ENTIRE home directory is a Git repo!
# Always cd into your project folder first
04Your First Commit — git add + git commit

A commit is a permanent snapshot stored in Git's history. It is the fundamental unit of work in Git — every project is built one commit at a time.

Two-step process: git add (stage changes) then git commit (create the snapshot). No shortcuts — you must stage before you commit.

git add . stages ALL changes. git add filename.txt stages one file. Choose what goes into the commit.

The commit message is CRITICAL: it explains WHY the change was made. Future you will thank present you for clear messages.

Good messages: "feat: add login page", "fix: handle null response". Bad messages: "update", "fix", "asdfgh".

After the first commit, you officially have history. git log works. Branches exist. You are no longer on an orphan branch.

# Create your first file
echo "# My Website" > README.md

# Check status — Git sees an untracked file
git status
# Untracked files: README.md

# Stage the file
git add README.md
# Or stage everything: git add .

# Status now shows it's staged
git status
# Changes to be committed: new file: README.md

# Commit — create the permanent snapshot
git commit -m "feat: initial commit with README"

# You have history now!
git log
# commit a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
# Author: Sai Kumar <sai@devinhyderabad.com>
# Date:   Mon Jan 6 10:00:00 2025 +0530
#
#     feat: initial commit with README
💡 Pro Tip: The commit message format type: description is called Conventional Commits. Types: feat (new feature), fix (bug fix), chore (maintenance), docs (documentation). Start using this from day 1 — your team and future self will thank you.
05Config File — ~/.gitconfig

All --global config settings are stored in ~/.gitconfig — a plain text file you can open in any editor.

You can edit it directly with a text editor instead of running git config commands. Sometimes it's faster to open the file and make multiple changes at once.

Local repo settings are in .git/config — only affect that repo. Global settings are the default; local settings are the exception.

Useful settings: init.defaultBranch, core.editor, push.default, pull.rebase, aliases.

git config --list --show-origin — see ALL config values and WHERE they come from. Essential for debugging config issues.

You can have different emails for work and personal projects using --local. This is the most common use case for local config.

# View your global config file
cat ~/.gitconfig
# [user]
#     name = Sai Kumar
#     email = sai@devinhyderabad.com
# [core]
#     editor = code --wait
# [init]
#     defaultBranch = main
# [alias]
#     st = status
#     co = checkout
#     lg = log --oneline --graph --all

# Edit it directly in VS Code
code ~/.gitconfig

# See ALL config (global + local + system) with sources
git config --list --show-origin

# Work vs Personal email setup
cd ~/work-project
git config --local user.email "sai@company.com"

cd ~/personal-project
git config --local user.email "sai@gmail.com"

# Verify per-repo
cd ~/work-project && git config user.email  # sai@company.com
cd ~/personal-project && git config user.email  # sai@gmail.com

Lo kar liya — Key Points:

  • ✅ Every commit is stamped with your name and email — set these with git config --global user.name and user.email BEFORE your first commit
  • ✅ Your Git email MUST match your GitHub/GitLab email or your commits won't link to your profile
  • ✅ Config priority: local (per-repo) > global (per-user) > system (per-machine) — use --local for work/personal email separation
  • git init creates the .git/ directory — it transforms a normal folder into a Git repository
  • ✅ Commits are a two-step process: git add (stage) then git commit (create permanent snapshot)
  • ✅ Good commit messages follow Conventional Commits: feat:, fix:, chore: — be specific, not vague
  • ✅ All global config is stored in ~/.gitconfig — you can edit it directly or via git config commands
Course Search
Search across all chapters & stages
📖

Search the course

Type any topic — branching, stash, rebase, hooks — and jump straight to that chapter.

merge branchesgit stashundo commitrebase