Lesson 52 of 55
PythonVersion Control with Git
20 minutes
Course progress95%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 52 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
Git is the most widely‑used distributed version‑control system. It lets you track changes, collaborate with teammates, and safely experiment with new features.
brew install git (Homebrew) or use the Xcode command‑line tools (xcode-select --install).sudo apt-get install git (Debian/Ubuntu) or sudo dnf install git (Fedora).# 1. Initialise a new repository (run inside your project folder)
git init
# 2. Stage files for the first commit
git add .
# 3. Commit with a message
git commit -m "Initial commit – project skeleton"
# Create a new branch for a feature
git checkout -b feature/login
# After working, stage & commit changes
git add login.py
git commit -m "Add login view"
# Switch back to main and merge
git checkout main
git merge feature/login
# Create a repo on GitHub, then link it locally
git remote add origin https://github.com/<username>/<repo>.git
# Push your local main branch
git push -u origin main
| Action | Command |
|---|---|
| View status | git status |
| See commit history | git log --oneline --graph --decorate |
| Discard local changes | git checkout -- <file> |
| Undo last commit (keep changes) | git reset --soft HEAD~1 |
| Stash work in progress | git stash / git stash pop |
Once you’re comfortable with these basics you’ll be ready to collaborate on any Python project.