Git and GitHub: Complete Version Control Guide

Why Git Is Non-Negotiable

Git is the version control system used by essentially every software team. Without it, collaborative development would be chaos. With it, you can experiment freely, knowing you can always go back.

First-Time Setup

git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global core.editor "code --wait"

Core Workflow

# Start a project
git init my-project
cd my-project

# Stage and commit
git add .
git commit -m "Initial commit: Add project structure"

# Check what changed
git status
git diff

Branching for Features

# Create feature branch
git checkout -b feature/user-auth

# Work on feature, then commit
git add auth.py
git commit -m "Add JWT authentication middleware"

# Merge back to main
git checkout main
git merge feature/user-auth
git branch -d feature/user-auth

GitHub Collaboration

# Connect to GitHub
git remote add origin https://github.com/username/repo.git
git push -u origin main

# Pull team changes
git pull origin main

# Fork and contribute
git clone https://github.com/someone/project.git

Undoing Mistakes

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Revert a specific commit
git revert abc1234

# Discard changes in a file
git checkout -- filename.py

Professional Git Practices

  • Write meaningful commit messages (what AND why)
  • One logical change per commit
  • Branch for every feature and bug fix
  • Review your diff before committing
  • Never rewrite history on shared branches

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top