Introduction to Git
What is Version Control?
The problem version control solves: tracking changes over time, collaborating without overwriting each other's work, and recovering from mistakes.
A brief history: from manual backups to CVS, Subversion, and distributed systems like Git.
Centralised vs distributed version control — why Git's distributed model gives every developer a full history.
Installing Git and verifying the installation on macOS, Linux, and Windows.
Start
Setting Up and Creating a Repository
First-time Git configuration: git config --global for name, email, default editor, and default branch name.
Initialising a new repository with git init and understanding the hidden .git directory.
Cloning an existing repository with git clone.
The three areas of a Git project: working directory, staging area (index), and repository (.git).
Start
Staging and Committing
The git add command: staging specific files, directories, and using git add -p for partial staging.
Writing a good commit message: the subject line, imperative mood, and the 50/72 rule.
git commit, git commit -m, and committing all tracked changes with git commit -am.
Viewing commit history with git log and useful flags: --oneline, --graph, --all, and --author.
Start
Inspecting and Undoing Changes
Checking what changed with git status and git diff (working directory vs staging vs last commit).
Unstaging files with git restore --staged and discarding working directory changes with git restore.
Amending the last commit with git commit --amend (only for local, unpushed commits).
Undoing commits safely with git revert (creates a new undo commit) vs git reset (rewrites history) — and when each is appropriate.
Start
Branching
What a branch is: a lightweight, movable pointer to a commit.
Creating, switching, and deleting branches: git branch, git switch, and git switch -c.
The HEAD pointer and detached HEAD state.
A practical branching workflow: always developing features on a separate branch, never directly on main.
Viewing all branches locally and remotely with git branch -a.
Start
Merging
Fast-forward merges vs three-way merges — when Git picks each strategy.
Merging a feature branch into main with git merge.
Merge conflicts: what causes them, how to read the conflict markers (<<<<, ====, >>>>), and how to resolve them.
Aborting a conflicted merge with git merge --abort.
Viewing a visual merge history with git log --graph.
Start
Rebasing
What rebase does: replaying commits on top of another branch for a linear history.
git rebase vs git merge — trade-offs and the golden rule of rebasing (never rebase shared history).
Interactive rebase with git rebase -i: reordering, squashing, editing, and dropping commits.
Using rebase to keep a feature branch up to date with main before merging.
Start
Working with Remote Repositories
What a remote is: git remote add, git remote -v, and the conventional origin name.
Fetching and pulling: git fetch (download without merging) vs git pull (fetch + merge).
Pushing changes with git push and setting the upstream with -u.
Tracking branches: the relationship between a local branch and its remote counterpart.
Handling a rejected push: fetching, resolving divergence, and pushing again.
Start
Pull Requests and Code Review
GitHub as a hosting platform: repositories, forks, and the difference between a collaborator and a fork-based contributor.
Opening a Pull Request: title, description, linking issues, and choosing the base branch.
The code review process: leaving comments, requesting changes, and approving.
Merging strategies on GitHub: merge commit, squash and merge, and rebase and merge.
Keeping a fork in sync with the upstream repository.
Start
Git Workflows for Teams
An overview of common team workflows: GitHub Flow (simple, PR-based), Git Flow (release branches), and trunk-based development.
Branch naming conventions and protection rules on GitHub (require PR review, status checks).
The .gitignore file: patterns for excluding build artefacts, node_modules, .env files, and OS files.
Using a global .gitignore for editor and OS noise.
Start
Tags, Stash, and Useful Commands
Tagging releases with git tag: lightweight tags vs annotated tags, and pushing tags to remote.
Saving work-in-progress temporarily with git stash: stash, pop, list, apply, and drop.
Finding the commit that introduced a bug with git bisect (binary search through history).
Tracing who wrote each line with git blame.
Cherry-picking a specific commit onto the current branch with git cherry-pick.
Start
Git in a Full-Stack JavaScript Project
A capstone walkthrough: initialising a repo, setting up .gitignore for a Node/React project, committing the first working version, creating a feature branch, opening a Pull Request, and merging it.
Automating checks on push with GitHub Actions: running lint and tests before allowing a merge.
Semantic versioning and using tags to mark releases.
Recommended Git GUIs: GitLens in VS Code, GitHub Desktop, and SourceTree — for those who prefer a visual interface alongside the CLI.
Start
