Why Version Control?
Version control tracks changes to files over time, enabling:
- Collaboration — Multiple people work on the same project
- History — See who changed what and when
- Rollback — Revert to any previous state
- Branching — Work on features without affecting stable code
Installing Git
# Ubuntu/Debian
sudo apt install git-all
# Verify
git --versionConfiguration
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
# View config
git config --listInitializing a Repository
mkdir my-project && cd my-project
git initThis creates a hidden .git directory that tracks everything.
The Git Workflow
Working Directory → Staging Area → Repository
(edit) (git add) (git commit)
Checking Status
git statusAdding Files
# Track a specific file
git add filename.txt
# Track multiple files
git add file1.txt file2.txt
# Track all changes (use carefully)
git add .Committing Changes
git commit -m "Add initial project files"Write clear, concise commit messages describing WHAT changed.
Viewing History
git log
git log --oneline
git log --oneline --graphDeleting Files
git rm filename.txt
git commit -m "Remove unused file"Practical Exercise
mkdir devops-lab && cd devops-lab
git init
echo "# My DevOps Project" > README.md
git add README.md
git commit -m "Initial commit: add README"
echo "print('hello')" > app.py
git add app.py
git commit -m "Add application entry point"
git log --onelineSummary
git initcreates a repositorygit addstages changesgit commit -m "message"records changesgit statusshows current stategit logshows history- Always commit with meaningful messages
Next Steps
Next, we'll cover branching, merging, and resolving conflicts.