
Every professional developer needs to understand Git and GitHub. At SwedTech Academy, we make sure all our students master these essential tools from day one.
Version control is a system that tracks changes to files over time. It allows you to:
Git is a version control system that runs on your computer. GitHub is a cloud platform for hosting Git repositories and collaborating with others.
Think of Git as your local photo album, and GitHub as Instagram where you share your photos.
# Check if Git is installed
git --version
# Install on macOS
brew install git
# Install on Windows
# Download from git-scm.com
# Install on Linux
sudo apt-get install git
# Set your name
git config --global user.name "Your Name"
# Set your email
git config --global user.email "[email protected]"
# Check configuration
git config --list
# Initialize new repository
git init
# Clone existing repository
git clone https://github.com/username/repo-name.git
# Check status
git status
# Add files to staging
git add filename.txt # Single file
git add . # All files
# Commit changes
git commit -m "Add new feature"
# Push to GitHub
git push origin main
Working Directory → Staging Area → Local Repository → Remote Repository
↓ ↓ ↓ ↓
(git add) (git commit) (git push)
Branches let you work on features independently:
# Create new branch
git branch feature-login
# Switch to branch
git checkout feature-login
# Create and switch (shortcut)
git checkout -b feature-login
# List all branches
git branch
# Merge branch into main
git checkout main
git merge feature-login
# Delete branch
git branch -d feature-login
# 1. Create feature branch
git checkout -b feature/add-search
# 2. Make changes and commit
git add .
git commit -m "Add search functionality"
# 3. Push to GitHub
git push origin feature/add-search
# 4. Create Pull Request on GitHub
# 5. After approval, merge and delete branch
git checkout main
git pull origin main
git branch -d feature/add-search
Merge conflicts happen when two branches modify the same line:
# When merge conflict occurs
git merge feature-branch
# Git will mark conflicts in files:
<<<<<<< HEAD
Current code in main branch
=======
Code from feature branch
>>>>>>> feature-branch
# Resolve conflicts by:
# 1. Edit files to keep desired code
# 2. Remove conflict markers
# 3. Add and commit
git add .
git commit -m "Resolve merge conflict"
# View commit history
git log
git log --oneline
git log --graph
# See changes before commit
git diff
# Discard changes in working directory
git checkout -- filename.txt
# Unstage files
git reset HEAD filename.txt
# Undo last commit (keep changes)
git reset --soft HEAD~1
# Update from remote
git pull origin main
# Show remote repositories
git remote -v
# Bad
git commit -m "fix"
git commit -m "update stuff"
# Good
git commit -m "Fix login button alignment on mobile"
git commit -m "Add email validation to signup form"
Make small, focused commits rather than large ones:
# .gitignore file
node_modules/
.env
.DS_Store
dist/
*.log
# Always pull latest changes before pushing
git pull origin main
git push origin main
# Add remote repository
git remote add origin https://github.com/username/repo-name.git
# Push to GitHub
git push -u origin main
Pull Requests are how you propose changes:
# Setup
git init # Initialize repository
git clone [url] # Clone repository
# Changes
git status # Check status
git add [file] # Stage file
git add . # Stage all
git commit -m "[msg]" # Commit changes
# Branching
git branch # List branches
git branch [name] # Create branch
git checkout [branch] # Switch branch
git merge [branch] # Merge branch
# Remote
git push origin [branch] # Push to remote
git pull origin [branch] # Pull from remote
git remote -v # Show remotes
# History
git log # Show history
git diff # Show changes
Mastering Git and GitHub is essential for every developer. In all our courses at SwedTech Academy:
Ready to become a professional developer? Join SwedTech Academy and master the tools of the trade!