Git & Version Control
Git & Version Control
Git is a distributed version control system that helps developers track changes to their
code over time. It enables multiple people to collaborate on the same codebase without
overwriting each other's work.
Real-Life Analogy:
Imagine writing a group project on a Word document. Everyone keeps sending different
versions via email (Final.docx, Final_Final.docx, Final_edited_by_Ayo.docx). It quickly
becomes confusing.
Now imagine a system where:
2. Git Basics
Here are the core Git commands and what they do, explained using a photographer’s
workflow:
git init
git init
git add
Stages changes (files) to be committed. It’s like choosing which photos to include in your
final album.
git commit
Takes a snapshot of the current state of the project — like saving the final version of
selected photos with a label.
git push
Scenario:
You’re done editing locally, and now you're uploading your photos to the cloud to share with
the team.
git pull
Scenario:
Your teammate added new photos to the shared album. You use git pull to download
them and update your local copy.
Scenario:
You want to experiment with black-and-white filters without affecting the original photos. You
create a "filter-test" copy. That’s your new branch.
To switch branches:
git merge
Scenario:
You like how your black-and-white edits turned out, and now you want to include them in the
main photo album. That’s a merge.
3. Using GitHub
GitHub is a cloud-based hosting platform for your Git repositories. It helps:
● Collaborate on projects
● Track issues
2.
3. Make changes and push
4. Open a Pull Request (PR) to review changes
5. Merge after approval
Bash scripts are used in DevOps to automate repetitive tasks like deployments, backups,
and configuration.
Basic Structure
#!/bin/bash
echo "Starting backup..."
cp -r /var/www /backup/site
echo "Backup completed!"
# File: backup.sh
DATE=$(date +%F)
BACKUP_DIR="/home/devops/backups/$DATE"
mkdir -p $BACKUP_DIR
cp -r /home/devops/projects/* $BACKUP_DIR
Make it executable:
chmod +x backup.sh
Then run:
./backup.sh
● Once approved, changes are merged into main and deployed to production via a
Bash deployment script
Class task:
Each student will contribute a section to a shared project — a simple HTML-based team
portfolio — using Git and GitHub.
The difference between Git and GitHub is like the difference between a tool and a website
that hosts projects made with that tool.
🔧 Git
● Git is a version control system.
● It lets you:
✅ Git is installed on your machine (e.g., via git init, git commit).
☁️ GitHub
● GitHub is a cloud platform that hosts Git repositories.
● It helps you:
✅ GitHub uses Git behind the scenes but adds a web UI, team tools, and hosting.
🔁 Relationship
You can use Git without GitHub, but you can't use GitHub without Git.
Would you like a visual diagram showing how they work together?