Development Tools and Version Control
Summary
This chapter covers essential development tools for Linux. Master Git version control from basic commits to branching and merging, learn to collaborate on GitHub, and set up Python development environments with virtual environments and package managers. Explore IDEs like VSCode and Thonny, and learn debugging techniques.
Concepts Covered
This chapter covers the following 25 concepts from the learning graph:
- Version Control
- Git Basics
- Git Init
- Git Clone
- Git Add
- Git Commit
- Git Push
- Git Pull
- Git Branch
- Git Merge
- GitHub
- GitHub Repositories
- GitHub SSH Keys
- Python on Linux
- Python3 Command
- Pip Package Manager
- Virtual Environments
- Venv Module
- Conda Environment
- VSCode on Linux
- Thonny IDE
- Code Editors
- Debugging Tools
- GDB Debugger
- Print Debugging
Prerequisites
This chapter builds on concepts from:
- Chapter 1: Introduction to Operating Systems and UNIX History
- Chapter 10: Text Editors: Nano and Vim
- Chapter 16: SSH and Remote Access
Welcome to Developer Mode! π οΈ
Congratulations! You've made it to the chapter where you stop being just a Linux user and start becoming a Linux developer. This is where the magic happensβwhere ideas become code, code becomes software, and software changes the world.
In this chapter, you'll learn: - How to track every change you make to your code (and undo mistakes!) - How to collaborate with developers around the world - How to set up professional Python development environments - Which tools make coding on Linux a joy
"First, solve the problem. Then, write the code." β John Johnson
Let's get you set up with the tools that professional developers use every day!
What is Version Control?
Version control is a system that tracks changes to files over time. Think of it as an unlimited "undo" button that also remembers why you made each change.
Why Version Control Matters
| Without Version Control | With Version Control |
|---|---|
project.py |
project.py |
project_v2.py |
(Git tracks all versions) |
project_v2_final.py |
|
project_v2_final_REALLY.py |
|
project_v2_final_REALLY_v3.py |
Sound familiar? Version control fixes this mess!
Benefits of Version Control
| Benefit | Description |
|---|---|
| History | See every change ever made |
| Undo | Revert to any previous version |
| Collaboration | Multiple people work on same project |
| Branching | Experiment without breaking main code |
| Backup | Code is stored safely (especially with GitHub) |
Git Pun Time
Why did the developer quit? Because he didn't get arrays! (a raise) π€
Git Basics: The Foundation
Git is the world's most popular version control system. Created by Linus Torvalds (yes, the Linux creator!) in 2005, Git is now used by virtually every software project.
Installing Git
1 2 3 4 5 | |
Configuring Git
Before your first commit, tell Git who you are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
The Three States of Git
Git files exist in three states:
1 2 | |
- Working Directory: Files you're editing
- Staging Area: Files ready to be committed
- Repository: Saved history of commits
Git Init: Starting a New Repository
Git init creates a new Git repository in your project folder.
1 2 3 4 5 6 7 8 9 10 | |
The .git folder contains all version history. Never delete it (unless you want to remove version control)!
Your First Repository
1 2 3 4 5 6 7 8 9 10 11 | |
Git Clone: Copying Existing Repositories
Git clone downloads an existing repository to your computer.
1 2 3 4 5 6 7 8 | |
Example: Clone a Real Project
1 2 3 4 5 | |
Git Add: Staging Changes
Git add moves files from your working directory to the staging area.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Understanding Staging
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Why have a staging area? It lets you: - Commit only some of your changes - Review what you're about to commit - Build commits that make logical sense
Git Commit: Saving Snapshots
Git commit saves your staged changes to the repository history.
1 2 3 4 5 6 7 8 | |
Writing Good Commit Messages
| Bad Message | Good Message |
|---|---|
| "fixed stuff" | "Fix login validation for empty passwords" |
| "update" | "Add user profile page with avatar upload" |
| "asdfasdf" | "Refactor database queries for better performance" |
| "WIP" | "Add initial draft of payment processing" |
Commit message format:
1 2 3 4 5 | |
Viewing History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Git Push: Sharing Your Work
Git push uploads your commits to a remote repository (like GitHub).
1 2 3 4 5 6 7 8 9 10 11 | |
The Remote-Local Relationship
1 2 3 4 5 | |
Git Pull: Getting Updates
Git pull downloads and merges changes from the remote repository.
1 2 3 4 5 6 7 8 | |
Fetch vs Pull
| Command | What It Does |
|---|---|
git fetch |
Downloads changes but doesn't merge |
git pull |
Downloads AND merges changes |
Use fetch when you want to see what changed before merging.
Git Branch: Parallel Development
Branches let you work on features without affecting the main code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
Branching Strategy
1 2 3 4 | |
Common branch names:
- main or master - Production-ready code
- develop - Integration branch
- feature/login - New feature
- bugfix/header-crash - Bug fix
- hotfix/security-patch - Urgent fix
Git Merge: Combining Branches
Git merge combines changes from one branch into another.
1 2 3 4 5 6 7 8 9 10 | |
Handling Merge Conflicts
When two branches modify the same lines, Git can't automatically merge. You'll see:
1 2 3 4 5 | |
To resolve:
1. Edit the file to keep the code you want
2. Remove the <<<<<<<, =======, and >>>>>>> markers
3. Stage and commit the resolved file
1 2 3 | |
Merge Conflict Tip
Don't panic when you see conflicts! They're normal. Take your time, understand both versions, and keep the best code.
GitHub: Where the World Codes
GitHub is the largest code hosting platform, home to millions of projects including Linux, Python, and VS Code.
Why GitHub?
| Feature | Description |
|---|---|
| Free hosting | Unlimited public repos, free private repos |
| Collaboration | Pull requests, code review, issues |
| Community | Follow projects, star favorites |
| CI/CD | GitHub Actions for automation |
| Pages | Free website hosting |
Creating a GitHub Account
- Go to github.com
- Sign up with your email
- Verify your email
- Set up your profile
GitHub Repositories
A GitHub repository is a project stored on GitHub.
Creating a New Repository
- Click the "+" button β "New repository"
- Choose a name
- Add a description
- Choose public or private
- Optionally add README, .gitignore, license
- Click "Create repository"
Connecting Local to GitHub
1 2 3 4 5 6 7 8 9 10 | |
GitHub SSH Keys: Secure Access
SSH keys let you connect to GitHub without entering your password every time.
Generating SSH Keys
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Adding SSH Key to GitHub
- Go to GitHub β Settings β SSH and GPG keys
- Click "New SSH key"
- Paste your public key
- Give it a title (e.g., "My Laptop")
- Click "Add SSH key"
Testing SSH Connection
1 2 | |
Using SSH URLs
1 2 3 4 5 | |
Python on Linux
Linux is a fantastic platform for Python development. Most distributions include Python pre-installed!
Python3 Command
1 2 3 4 5 6 7 8 9 10 11 12 | |
Python 2 vs Python 3
Always use python3, not python. On some systems, python still refers to Python 2 (which is obsolete). Python 3 is the present and future!
Installing Python
1 2 3 4 5 6 7 8 | |
Pip Package Manager
Pip is Python's package managerβit installs libraries from PyPI (Python Package Index).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Requirements Files
Create a requirements.txt to share dependencies:
1 2 3 4 5 | |
Generate from current environment:
1 | |
Virtual Environments: Isolation is Key
Virtual environments create isolated Python installations for each project. This prevents dependency conflicts between projects!
Why Virtual Environments?
| Without Venv | With Venv |
|---|---|
| Project A needs Django 3.0 | Project A venv has Django 3.0 |
| Project B needs Django 4.0 | Project B venv has Django 4.0 |
| CONFLICT! Only one can be installed | Both work perfectly! β |
Venv Module: Python's Built-in Solution
The venv module creates virtual environments without installing anything extra.
1 2 3 4 5 6 7 8 9 10 11 12 | |
Complete Workflow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Venv Best Practices
| Practice | Why |
|---|---|
Name it venv or .venv |
Standard, recognizable |
Add venv/ to .gitignore |
Don't commit dependencies |
Keep requirements.txt updated |
Reproducible environment |
| One venv per project | Clean isolation |
1 2 | |
Conda Environment
Conda is an alternative package/environment manager that handles Python AND non-Python dependencies (like C libraries).
Installing Miniconda
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Using Conda Environments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Conda vs Venv
| Feature | venv | Conda |
|---|---|---|
| Built into Python | β | β (must install) |
| Python packages | β | β |
| Non-Python deps | β | β |
| Multiple Python versions | β | β |
| Size | Light | Heavy |
| Best for | Pure Python | Data science, ML |
Code Editors: Your Digital Workshop
A code editor is where you write code. Choosing the right one can make coding more enjoyable and productive!
Popular Code Editors for Linux
| Editor | Type | Best For |
|---|---|---|
| VSCode | Full IDE | Most developers |
| Thonny | Simple IDE | Python beginners |
| Vim | Terminal | Speed, server work |
| Nano | Terminal | Quick edits |
| PyCharm | Full IDE | Python professionals |
| Sublime Text | Editor | Fast, lightweight |
VSCode on Linux
Visual Studio Code (VSCode) is the most popular code editor, with excellent Linux support.
Installing VSCode
1 2 3 4 5 6 7 8 9 10 | |
Essential VSCode Extensions
| Extension | Purpose |
|---|---|
| Python | Python support |
| Pylance | Advanced Python features |
| GitLens | Enhanced Git integration |
| Remote - SSH | Edit files on remote servers |
| Markdown Preview | Preview markdown files |
| Docker | Docker integration |
VSCode Tips
1 2 3 4 5 6 7 8 9 10 11 | |
Useful shortcuts:
| Shortcut | Action |
|----------|--------|
| Ctrl+P | Quick open file |
| Ctrl+Shift+P | Command palette |
| Ctrl+`` | Toggle terminal |
|Ctrl+B| Toggle sidebar |
|Ctrl+/| Toggle comment |
|F5` | Start debugging |
Thonny IDE
Thonny is a simple, beginner-friendly Python IDE that comes pre-installed on Raspberry Pi OS.
Why Thonny?
| Feature | Benefit |
|---|---|
| Simple interface | No overwhelming menus |
| Built-in debugger | Step through code easily |
| Variable inspector | See values in real-time |
| MicroPython support | Program microcontrollers |
| Beginner focus | Designed for learning |
Installing Thonny
1 2 3 4 5 6 7 8 | |
Thonny Features
- Step-through debugging - Run code line by line
- Variable view - Watch variables change
- Shell - Test code interactively
- Syntax highlighting - Code is color-coded
- MicroPython - Connect to Raspberry Pi Pico
Thonny for Learning
If you're new to Python, start with Thonny! Its simple interface lets you focus on learning to code, not learning the editor. You can always switch to VSCode later.
Debugging Tools: Finding Bugs
Debugging is the process of finding and fixing errors in your code. It's a crucial skill that separates beginners from professionals!
Types of Bugs
| Bug Type | Example |
|---|---|
| Syntax Error | Missing colon, wrong indentation |
| Runtime Error | Division by zero, file not found |
| Logic Error | Wrong formula, off-by-one error |
Print Debugging: The Classic Approach
Print debugging is the simplest techniqueβadd print statements to see what's happening.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Better Print Debugging
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Python Debugging with pdb
pdb is Python's built-in debugger.
1 2 3 4 5 | |
pdb commands:
| Command | Action |
|---------|--------|
| n | Next line |
| s | Step into function |
| c | Continue to next breakpoint |
| p variable | Print variable value |
| l | List source code |
| q | Quit debugger |
| h | Help |
VSCode Debugging
VSCode has an excellent visual debugger:
- Set breakpoints by clicking line numbers
- Press F5 to start debugging
- Use debug controls (continue, step over, step into)
- Watch variables in the sidebar
- Use the debug console for expressions
GDB Debugger: For C/C++ and More
GDB (GNU Debugger) is the standard debugger for C, C++, and other compiled languages.
Installing GDB
1 | |
Basic GDB Usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
GDB Example Session
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Complete Development Workflow
Here's how all these tools work together:
1. Start a New Project
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
2. Connect to GitHub
1 2 3 | |
3. Daily Development
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
4. Keep Dependencies Updated
1 2 3 4 5 6 | |
Review Questions
What are the three states of Git files, and what does each state mean?
The three states are: (1) Modified - files have been changed in the working directory but not staged, (2) Staged - files have been marked with git add and are ready to be committed, (3) Committed - files have been safely stored in the local repository. Understanding this workflow helps you track which changes are ready to be saved and which are still in progress.
What is the difference between git fetch and git pull?
git fetch downloads changes from the remote repository but doesn't merge them into your local branch - it just updates your remote-tracking branches. git pull does both: it fetches changes AND automatically merges them into your current branch. Use fetch when you want to see what changed before merging, and pull when you're ready to integrate the changes immediately.
Why should you use virtual environments for Python projects?
Virtual environments isolate each project's dependencies from the system Python and from other projects. Without them, you might have conflicts where Project A needs Django 3.0 but Project B needs Django 4.0 - you can only have one version installed globally. With virtual environments, each project has its own isolated Python with its own packages, so they never conflict.
What is the purpose of SSH keys for GitHub, and how do they work?
SSH keys provide secure, password-less authentication to GitHub. You generate a key pair (private and public), add the public key to your GitHub account, and keep the private key on your computer. When you push or pull, SSH uses your private key to prove your identity. This is more secure than passwords and more convenient since you don't need to enter credentials for every operation.
What is the difference between print debugging and using a debugger like pdb?
Print debugging adds print statements to show variable values and execution flow - it's simple but requires modifying code and rerunning. A debugger like pdb lets you pause execution at any point, inspect all variables, step through code line by line, and even change values mid-execution without modifying the source code. Debuggers are more powerful but have a learning curve; print debugging is quick for simple issues.
Chapter Summary
You're now equipped with the essential tools of a professional developer! Let's recap:
Version Control with Git:
- Initialize repos with git init, clone with git clone
- Stage with git add, commit with git commit
- Push to share, pull to update
- Branch for features, merge to integrate
GitHub Collaboration: - Host your code in repositories - Use SSH keys for secure access - Collaborate with pull requests
Python Development:
- Use python3 and pip3 always
- Create virtual environments with venv
- Use Conda for complex dependencies
- Keep requirements.txt updated
Code Editors: - VSCode for full-featured development - Thonny for Python beginners - Vim/Nano for terminal editing
Debugging: - Print debugging for quick checks - pdb for Python stepping - GDB for compiled languages - VSCode debugger for visual debugging
These tools form the foundation of professional software development. Master them, and you'll be ready to contribute to open-source projects, collaborate with teams, and build amazing software!
Keep coding, keep committing, and remember: every expert was once a beginner who refused to give up! ππ»
References
- Git Official Documentation - Complete Git reference including commands, workflows, and advanced features.
- Pro Git Book (Free) - Comprehensive free book covering Git from basics to advanced topics.
- GitHub Documentation - Official guide to using GitHub including repositories, pull requests, and collaboration.
- GitHub Learning Lab - Interactive tutorials for learning Git and GitHub through hands-on practice.
- Python Official Documentation - Complete Python language reference and library documentation.
- pip Documentation - Official guide to Python's package installer and dependency management.
- Python Virtual Environments Guide - Official tutorial for creating isolated Python environments with venv.
- Visual Studio Code Documentation - Complete VSCode guide including setup, extensions, and debugging.
- Thonny Python IDE - Beginner-friendly Python IDE with built-in debugger and MicroPython support.
- GitHub SSH Key Setup - Setting up SSH keys for secure, password-less GitHub authentication.
- Conda Documentation - Guide to using Conda for package and environment management including non-Python dependencies.
- Git Branching Strategy - Popular Git Flow branching model for team collaboration.
- Python pdb Debugger Tutorial - Using Python's built-in debugger for step-through debugging.
- GDB Documentation - GNU Debugger guide for C/C++ and other compiled languages.
- VSCode Python Extension - Official Python extension adding IntelliSense, debugging, and testing.
- GitLens Extension - Enhanced Git integration for VSCode with blame, history, and visualization.
- Writing Good Commit Messages - Best practices for clear, helpful Git commit messages.
- GitHub Flow Guide - Simple branching strategy for continuous deployment and collaboration.
- Python Logging Tutorial - Using Python's logging module instead of print debugging.
- GeeksforGeeks: Git Tutorial - Beginner-friendly Git tutorial with examples and common workflows.