Introduction
Git is a distributed version‑control system that lets you track changes, collaborate with others, and manage code efficiently.
Installation
Download Git from the official site or use a package manager.
brew install git # macOS (Homebrew)
sudo apt-get install git # Ubuntu/Debian
choco install git # Windows (Chocolatey)
Basic Configuration
Set your identity so that commits are properly attributed.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor "code --wait"
Common Commands
Initialize a Repository
git init
Clone a Remote Repository
git clone https://github.com/user/repo.git
Check Status
git status
Add Files
git add .
Commit Changes
git commit -m "Your message"
Push to Remote
git push origin main
Branching & Merging
Create and switch to a new branch:
git checkout -b feature/login
Merge a branch into the current branch:
git merge feature/login
Stashing
Temporarily store changes:
git stash
Apply the most recent stash:
git stash pop