Git & GitHub
Every professional developer uses Git daily. It's version control โ a time machine for your code. GitHub is where teams collaborate. These skills are non-negotiable for any job.
Git tracks every change you make to every file, lets you name those snapshots (commits), go back to any point in time, and work on different versions (branches) simultaneously.
| Concept | Meaning |
|---|---|
| Repository (repo) | A folder tracked by Git โ contains all files + history |
| Commit | A saved snapshot of your changes with a message |
| Branch | An independent line of development |
| Merge | Combine changes from two branches |
| Remote | A copy of the repo on a server (GitHub) |
| Clone | Download a remote repo to your machine |
| Push | Upload your local commits to remote |
| Pull | Download and merge remote changes to local |
Install Git
Windows: Download from git-scm.com โ run installer (all defaults are fine).
Mac: brew install git or it installs when you run git --version.
Linux: sudo apt install git
Configure your identity
Verify
Team Branching Workflow (GitFlow simplified)
| Branch | Purpose | Rule |
|---|---|---|
main | Production-ready code | Never commit directly |
develop | Integration branch | Features merged here first |
feature/xxx | New feature work | Branch from develop, merge back to develop |
fix/xxx | Bug fix | Branch from main or develop |
Create feature branch and push
Open PR on GitHub
GitHub shows a "Compare & pull request" banner when you push a new branch. Click it. Fill in the PR title and description explaining WHAT you changed and WHY.
Code review and merge
Reviewers leave comments. Address feedback by pushing more commits to the same branch โ the PR updates automatically. Once approved, merge the PR.
A merge conflict happens when two branches changed the same line(s) of the same file. Git can't decide which version to keep โ you have to resolve it manually.
Open the conflicted file in VS Code
VS Code highlights conflicts and shows "Accept Current", "Accept Incoming", or "Accept Both" buttons โ use them!
Resolve and save
Delete the conflict markers (<<<, ===, >>>) and keep the correct code. Save the file.
Commit the resolution
Git is a distributed version control system that tracks changes to files over time. We use it to: maintain history of every change (who changed what and why), collaborate with teams without overwriting each other's work, experiment safely with branches, revert to any previous state, and enable CI/CD pipelines.
git fetch downloads changes from the remote repository but does NOT merge them into your working branch. It updates your remote-tracking branches (origin/main) but your local main stays unchanged. Safe to run anytime.
git pull = git fetch + git merge. Downloads changes AND immediately merges them into your current branch. Use when you're ready to incorporate remote changes.
A merge conflict occurs when two branches have modified the same lines of the same file. Git can't automatically choose which version to keep.
To resolve: open the conflicted file (Git marks conflicts with <<<, ===, >>> markers), manually decide the correct code, remove the markers, save the file, stage it with git add, and commit.
git merge creates a new "merge commit" that combines two branches. It preserves the full history of both branches. The branch history is non-linear but authentic.
git rebase moves or "replays" your commits on top of another branch's tip. It creates a linear history โ looks like you branched from the latest commit. Cleaner history but rewrites commit hashes.
Rule: Use merge for shared/public branches. Use rebase for your local feature branches before creating a PR (to clean up history).
CI (Continuous Integration) โ Every code push triggers an automated build and test run. Catches bugs immediately when code is merged. Tools: GitHub Actions, Jenkins, GitLab CI.
CD (Continuous Deployment/Delivery) โ After CI passes, code is automatically deployed to staging or production. Every passing build can go live without manual steps.