Git is a change-tracking system — a form of Version Control (Source Control). It tracks modifications, stores history, and manages collaboration. Git is optimized for line-by-line tracking, not binary files.
A commit is a snapshot of your entire project at a specific moment.
Each commit includes:
HEAD points to the latest commit of the currently checked-out branch.
Every developer has a full copy of the repository.
git init # Initialize a new repository
git status # Show current branch, staged changes, and unstaged changes
git add . # Stage all modified files
git add <file> # Stage specific file
git commit -m "message" # Commit staged changes
git diff # Show unstaged changes
git diff --staged # Show staged changes
git log # Full commit history
git log --graph # Visual branch diagram
git log --oneline # One-line-per-commit view
git log --all # Logs from all branches
git reflog # Shows every HEAD movement (great for recovery)
git revert <commit> # Safe: creates a commit that undoes another
git reset <commit> # Dangerous: rewrites history
git restore <file> # Discard working directory changes
git restore --staged <file> # Unstage a file
git branch # List local branches
git branch -a # List local + remote branches
git checkout -b <name> # Create and switch to new branch
git switch <branch> # Modern branch switching
git checkout <branch> # Traditional branch switching
git branch -d <branch> # Delete merged branch
git merge <branch> # Merge branch into current
git stash # Save uncommitted changes
git stash list # View saved stashes
git stash push -m "message" # Save stash with description
git stash pop # Apply & remove latest stash
git stash apply # Apply stash without removing
git push -u origin main # Push commits to remote (+ set upstream)
git pull # Fetch + merge remote updates
git fetch # Fetch without merging
Use consistent prefixes:
feature/<description>bugfix/<issue>hotfix/<critical-fix>Reference: https://conventional-branch.github.io/
A merge conflict occurs when two commits modify the same part of a file.
Steps: