Day 1: Git Fundamentals

Git Fundamentals

Understanding Version Control Concepts

Before diving into commands, let’s understand what makes Git special. Unlike older systems that store differences between file versions, Git thinks of data as snapshots. Every time you commit, Git takes a picture of your entire project at that moment.

Complete Git Installation Guide for All Operating Systems

Windows Installation

Method 1: Official Git for Windows (Recommended)

  1. Download from git-scm.com
  2. Run the installer with these recommended settings:
    • ✅ Use Git from the command line and 3rd-party software
    • ✅ Use the OpenSSL library
    • ✅ Checkout Windows-style, commit Unix-style line endings
    • ✅ Use MinTTY (the default terminal of MSYS2)
    • ✅ Enable file system caching
    • ✅ Enable Git Credential Manager

Method 2: Package Managers

powershell

# Using Chocolatey
choco install git

# Using Scoop
scoop install git

# Using Winget
winget install Git.Git

Method 3: GitHub Desktop (GUI + CLI)

macOS Installation

Method 1: Homebrew (Recommended)

bash

# Install Homebrew first if not installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Git
brew install git

# Update Git
brew upgrade git

Method 2: MacPorts

bash

sudo port install git

Method 3: Official Installer

Method 4: Xcode Command Line Tools

bash

xcode-select --install

Linux Installation

Ubuntu/Debian:

bash

# Update package list
sudo apt update

# Install Git
sudo apt install git

# Install latest version from PPA
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git

CentOS/RHEL/Fedora:

bash

# CentOS/RHEL 7/8
sudo yum install git
# or
sudo dnf install git

# Fedora
sudo dnf install git

Arch Linux:

bash

sudo pacman -S git

openSUSE:

bash

sudo zypper install git

Alpine Linux:

bash

apk add git

Compile from Source (Any Linux):

bash

# Install dependencies (Ubuntu/Debian)
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libncurses5-dev libautotools-dev

# Download and compile
wget https://github.com/git/git/archive/v2.42.0.tar.gz
tar -xzf v2.42.0.tar.gz
cd git-2.42.0
make configure
./configure --prefix=/usr/local
make all
sudo make install

Verification

bash

# Check Git version
git --version

# Should output something like: git version 2.42.0

# Check installation path
which git
# macOS/Linux: /usr/bin/git or /usr/local/bin/git
# Windows: /c/Program Files/Git/bin/git

Essential Configuration Setup

Required Identity Configuration

bash

# Set your identity (REQUIRED for commits)
git config --global user.name "John Doe"
git config --global user.email "john.doe@example.com"

# Verify configuration
git config --global --list

Core Configuration Settings

bash

# Set default branch name to 'main'
git config --global init.defaultBranch main

# Enable colored output
git config --global color.ui auto
git config --global color.branch auto
git config --global color.diff auto
git config --global color.status auto

# Set default editor
git config --global core.editor "nano"           # Nano (simple)
git config --global core.editor "vim"            # Vim
git config --global core.editor "code --wait"    # VS Code
git config --global core.editor "subl -w"        # Sublime Text
git config --global core.editor "atom --wait"    # Atom

# Line ending configuration
# Windows
git config --global core.autocrlf true
# macOS/Linux
git config --global core.autocrlf input

Advanced Configuration

bash

# Improve performance
git config --global core.preloadindex true
git config --global core.fscache true
git config --global gc.auto 256

# Better diff algorithm
git config --global diff.algorithm patience

# Auto-correct mistyped commands (1 = 0.1 seconds delay)
git config --global help.autocorrect 1

# Set default push behavior
git config --global push.default simple

# Enable credential caching
# Linux/macOS
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'

# Windows (using Git Credential Manager)
git config --global credential.helper manager-core

# Set up pull behavior
git config --global pull.rebase false  # merge (default)
# OR
git config --global pull.rebase true   # rebase
# OR
git config --global pull.ff only       # fast-forward only

SSH Key Setup for Secure Authentication

bash

# Generate SSH key pair
ssh-keygen -t ed25519 -C "your.email@example.com"
# Press Enter for default location (~/.ssh/id_ed25519)
# Enter passphrase (recommended for security)

# Start SSH agent
# macOS/Linux
eval "$(ssh-agent -s)"

# Windows (Git Bash)
eval $(ssh-agent -s)

# Add key to SSH agent
ssh-add ~/.ssh/id_ed25519

# Copy public key to clipboard
# macOS
pbcopy < ~/.ssh/id_ed25519.pub

# Linux
xclip -selection clipboard < ~/.ssh/id_ed25519.pub

# Windows
clip < ~/.ssh/id_ed25519.pub

# Add to GitHub/GitLab/Bitbucket in SSH Keys settings

GPG Signing Setup (Optional but Recommended)

bash

# List existing GPG keys
gpg --list-secret-keys --keyid-format=long

# Generate new GPG key
gpg --full-generate-key
# Choose: RSA and RSA, 4096 bits, no expiration

# Get GPG key ID
gpg --list-secret-keys --keyid-format=long
# Copy the key ID after "sec   rsa4096/"

# Export public key
gpg --armor --export YOUR_KEY_ID

# Configure Git to use GPG
git config --global user.signingkey YOUR_KEY_ID
git config --global commit.gpgsign true
git config --global tag.gpgsign true

# Set GPG program (if needed)
git config --global gpg.program gpg

Configuration Verification

bash

# View all global configuration
git config --global --list

# View specific configuration
git config --global user.name
git config --global user.email

# View configuration with origins
git config --list --show-origin

# Test SSH connection (GitHub example)
ssh -T git@github.com

# Test GPG signing
echo "test" | gpg --clearsign

Platform-Specific Tips

Windows:

  • Use Git Bash for consistent Unix-like commands
  • Consider Windows Subsystem for Linux (WSL) for better integration
  • PowerShell users: Install posh-git for enhanced prompt

macOS:

  • Install latest Git via Homebrew (Apple’s version is often outdated)
  • Consider iTerm2 with Oh My Zsh for better terminal experience

Linux:

  • Most distributions include Git, but versions may be outdated
  • Compile from source for latest features
  • Consider Zsh with Oh My Zsh plugins

Git Repository Anatomy

Every Git repository contains these key components:

Working Directory: Your project files as you see them Staging Area (Index): A preview of your next commit .git Directory: Where Git stores all version history and metadata

Your First Repository

bash

# Create a new project directory
mkdir my-awesome-project
cd my-awesome-project

# Initialize Git repository
git init

# Check repository status
git status

Hands-On Exercise: Create a simple project structure and initialize Git. Notice how Git tracks the repository state even before your first commit.

You Might Also Like

🛠️ Recommended Tools for Developers & Tech Pros

Save time, boost productivity, and work smarter with these AI-powered tools I personally use and recommend:

1️⃣ CopyOwl.ai – Research & Write Smarter
Write fully referenced reports, essays, or blogs in one click.
✅ 97% satisfaction • ✅ 10+ hrs saved/week • ✅ Academic citations

2️⃣ LoopCV.pro – Build a Job-Winning Resume
Create beautiful, ATS-friendly resumes in seconds — perfect for tech roles.
✅ One-click templates • ✅ PDF/DOCX export • ✅ Interview-boosting design

3️⃣ Speechify – Listen to Any Text
Turn articles, docs, or PDFs into natural-sounding audio — even while coding.
✅ 1,000+ voices • ✅ Works on all platforms • ✅ Used by 50M+ people