Collaborate Smarter: Version Control with Git & GitHub
A practical guide to Git version control and GitHub collaboration, covering repositories, commits, branches, merging, pull requests, and real-world team workflows.
// table of contents (37 sections)
If you’ve ever had files like final_v2_REAL_FINAL.docx, you need Git.
Version control is not optional in professional development. Every company, every team, every serious project uses it. This guide covers the essentials you need to collaborate effectively.
What is Version Control?
Version control is a system that records changes to files over time so you can recall specific versions later.
Without Git
project/
├── main.dart
├── main_backup.dart
├── main_old.dart
├── main_final.dart
├── main_REAL_final.dart
└── main_please_work.dart
With Git
project/
├── .git/ ← Everything tracked here
└── main.dart ← Just one file, full history saved
Git lets you:
- Track every change with a message explaining why
- Go back to any previous version
- Work on features in parallel with branches
- Collaborate without overwriting each other’s work
Git vs GitHub
These are not the same thing:
| Git | GitHub | |
|---|---|---|
| What | Version control tool | Code hosting platform |
| Where | Runs on your machine | Runs in the cloud |
| Does | Tracks changes, branching, merging | Stores repos, PRs, issues, CI/CD |
| Needed? | Yes, always | Optional (but highly recommended) |
Other Git hosting platforms: GitLab, Bitbucket, Gitea.
Setup
Install Git
# macOS
brew install git
# Ubuntu/Debian
sudo apt install git
# Verify
git --version
Configure
git config --global user.name "Muhammad Abdu Ar Rahman"
git config --global user.email "your@email.com"
# Optional: set default branch name
git config --global init.defaultBranch main
SSH Key (for GitHub)
# Generate key
ssh-keygen -t ed25519 -C "your@email.com"
# Copy public key
cat ~/.ssh/id_ed25519.pub
# Paste in GitHub → Settings → SSH and GPG Keys → New SSH Key
Repository Basics
A repository (repo) is a project folder tracked by Git.
Create a New Repo
# Initialize in existing folder
mkdir my-project && cd my-project
git init
# Or clone an existing repo
git clone git@github.com:username/repo.git
The Three Areas
Understanding these three areas is the key to understanding Git:
Working Directory → Staging Area → Repository
(where you edit) (git add) (git commit)
| Area | Command | What It Holds |
|---|---|---|
| Working directory | Your files | Current state of files |
| Staging area | git add | Changes ready to commit |
| Repository | git commit | Permanent history |
Core Commands
The Daily Workflow
# 1. Check what changed
git status
# 2. See the actual changes
git diff
# 3. Stage specific files
git add main.dart
git add . # Stage everything
# 4. Commit with a message
git commit -m "Add login validation logic"
# 5. Push to remote
git push origin main
Viewing History
# Full log
git log
# Compact log
git log --oneline
# Visual branch graph
git log --oneline --graph --all
# See who changed what
git blame main.dart
Undoing Things
# Unstage a file (keeps your changes)
git reset HEAD main.dart
# Discard changes in a file (WARNING: permanent)
git checkout -- main.dart
# Undo last commit (keeps changes staged)
git reset --soft HEAD~1
# Undo last commit (discards changes)
git reset --hard HEAD~1
Be careful with
--hard. It permanently deletes uncommitted changes. Only use it when you’re certain.
Branching
Branches let you work on different features in parallel without affecting the main code.
Why Branch?
main: A — B — C ———————————————— M (merge)
\ /
feature: D — E — F — G ———/
mainstays stable while you experiment- Each feature gets its own branch
- Merge only when the feature is complete and tested
Branch Commands
# Create and switch to a new branch
git checkout -b feature/login
# Or with newer syntax
git switch -c feature/login
# Switch between branches
git switch main
git switch feature/login
# List all branches
git branch -a
# Delete a merged branch
git branch -d feature/login
Branch Naming Conventions
feature/add-user-profile
bugfix/fix-login-crash
hotfix/patch-security-issue
refactor/simplify-auth-logic
Merging & Resolving Conflicts
Merge a Branch
# Switch to target branch
git switch main
# Merge feature branch into it
git merge feature/login
# Push the result
git push origin main
Merge Conflicts
When two branches modify the same line, Git can’t auto-merge. You get a conflict:
<<<<<<< HEAD (main)
print('Welcome back, $name!');
=======
print('Hello, $name!');
>>>>>>> feature/login
Resolution steps:
- Open the conflicted file
- Choose which version to keep (or combine both)
- Remove the conflict markers (
<<<<<<<,=======,>>>>>>>) - Stage and commit
# After resolving conflicts
git add .
git commit -m "Merge feature/login, resolve greeting conflict"
Rebase (Alternative to Merge)
Rebase replays your commits on top of another branch, creating a cleaner history:
git switch feature/login
git rebase main
| Merge | Rebase |
|---|---|
| Preserves complete history | Creates linear history |
| Creates a merge commit | No merge commit |
| Safe for shared branches | Can cause issues on shared branches |
| Use for: merging features | Use for: cleaning up local work |
Rule of thumb: Never rebase commits that have been pushed to a shared branch.
Remote Repositories
Connecting to GitHub
# Add a remote
git remote add origin git@github.com:username/repo.git
# View remotes
git remote -v
# Push and set upstream
git push -u origin main
# After first push, just use
git push
Syncing with Remote
# Download new changes (don't merge)
git fetch origin
# Download and merge
git pull origin main
# Pull with rebase (cleaner history)
git pull --rebase origin main
Forking Workflow (Open Source)
1. Fork the repo on GitHub (creates your copy)
2. Clone your fork
3. Create a feature branch
4. Make changes and commit
5. Push to your fork
6. Open a Pull Request to the original repo
Pull Requests
A Pull Request (PR) is a request to merge your changes into another branch. It’s where code review happens.
Creating a PR
# 1. Push your feature branch
git push origin feature/login
# 2. Go to GitHub → your repo → "Compare & pull request"
# 3. Write a clear title and description
# 4. Request reviewers
# 5. Wait for approval
# 6. Merge when approved
Good PR Description
## What
Add email/password login validation
## Why
Users could submit empty forms, causing server errors
## Changes
- Add email format validation with regex
- Add password minimum length check (8 chars)
- Show error messages for invalid input
## Testing
- [ ] Empty email shows error
- [ ] Invalid email format shows error
- [ ] Short password shows error
- [ ] Valid credentials pass through
Code Review Etiquette
As reviewer:
- Be constructive, not critical
- Explain why something should change
- Approve when you’re satisfied
As author:
- Keep PRs small and focused
- Respond to every comment
- Push fixes as new commits (don’t force-push during review)
.gitignore
Not everything belongs in Git. Create a .gitignore file:
# Dependencies
node_modules/
vendor/
# Build output
dist/
build/
*.exe
# IDE
.vscode/
.idea/
*.swp
# OS files
.DS_Store
Thumbs.db
# Environment variables (IMPORTANT)
.env
.env.local
# Sensitive files
*.key
*.pem
credentials.json
Team Workflow
Feature Branch Workflow (Most Common)
1. git switch main
2. git pull origin main
3. git switch -c feature/new-feature
4. Code, commit, commit, commit...
5. git push origin feature/new-feature
6. Open Pull Request
7. Team reviews
8. Merge to main
9. Delete feature branch
10. git pull origin main (everyone syncs)
Commit Message Convention
type(scope): description
feat(auth): add login validation
fix(api): handle null response from server
docs(readme): update installation steps
refactor(utils): simplify date formatting
test(auth): add login unit tests
chore(deps): update dependencies
| Type | When |
|---|---|
feat | New feature |
fix | Bug fix |
docs | Documentation |
refactor | Code cleanup (no behavior change) |
test | Adding tests |
chore | Maintenance tasks |
Quick Reference
| Task | Command |
|---|---|
| Init repo | git init |
| Clone repo | git clone <url> |
| Check status | git status |
| Stage changes | git add . |
| Commit | git commit -m "message" |
| Push | git push origin main |
| Pull | git pull origin main |
| Create branch | git switch -c feature/name |
| Switch branch | git switch main |
| Merge branch | git merge feature/name |
| View log | git log --oneline |
What’s Next?
With version control mastered, you’re ready to learn about databases and SQL so your apps can store and retrieve data properly.
Bismillah, happy committing! 🚀
You might also like
Building Type-Safe APIs with tRPC in 2026: Full-Stack TypeScript Without Schemas
Learn how tRPC eliminates the need for API schemas by leveraging TypeScript's type system. Build end-to-end type-safe APIs with automatic client generation.
Rate Limiting Strategies for APIs: Protect Your Backend in 2026
Master API rate limiting with practical strategies and implementations. Compare token bucket, sliding window, and fixed window algorithms with real code examples in Go, Node.js, and Redis.
WebGPU Demystified: GPU Computing in the Browser
Learn WebGPU from scratch: modern GPU computing in the browser with TypeScript examples. Build high-performance graphics and compute applications.
More Posts
API Gateway Patterns: The Front Door to Your Microservices
Web Components 2026: Building Framework-Agnostic UI Libraries
Building Autonomous AI Workflows with LangGraph: A Practical Guide
Building Type-Safe APIs with tRPC in 2026: Full-Stack TypeScript Without Schemas
Database Connection Pooling: Patterns for High-Performance Applications
Prompt Caching: Reduce LLM Costs by 90% with Smart Context Management
Enjoyed This Post?
Want to discuss the topic, have questions, or looking to collaborate on something similar? Drop a comment below or reach out directly.
