Git Explained: Branching, Merging, and Workflows for Developers
Git is the version control system used by virtually every software team on the planet. Yet many developers use it mechanically — commit, push, merge — without understanding what's actually happening under the hood. This guide explains Git's core model so you can use it confidently, resolve conflicts without fear, and collaborate effectively on any team.
Git's Core Model: Snapshots, Not Diffs
Unlike older version control systems that stored differences between files, Git stores snapshots of the entire project at each commit. A commit is a point-in-time photograph of all your files, linked to its parent commit(s). This makes branching and merging cheap and fast — operations that were slow and painful in older systems.
Commits: The Unit of Work
A commit records who changed what, when, and why. The commit message is not decoration — it's documentation for your future self and teammates. The subject line should complete the sentence "If applied, this commit will...". Keep it under 72 characters. Add a body if the why needs more explanation.
Good: Add rate limiting to the authentication endpoint
Bad: fix stuff, updates, wip
Branches: Parallel Lines of Work
A branch is simply a pointer to a commit. Creating a branch is instantaneous — Git just creates a new pointer. This makes branches cheap to create and disposable when done. Common branch types:
- main/master: the production-ready baseline
- feature/description: new functionality in development
- fix/bug-description: bug fixes
- release/v1.2.0: release preparation branch
Merging vs Rebasing
Merge combines two branches by creating a new "merge commit" that has two parents. It preserves the full history of both branches exactly as it happened. Rebase replays your branch's commits on top of another branch, rewriting history to appear as if you'd always branched from the latest point. The result is a cleaner, linear history — but you've rewritten commits.
Merge Conflicts: What They Are and How to Resolve Them
A merge conflict occurs when two branches modify the same part of the same file in incompatible ways. Git marks the conflict in the file with <<<<<<<, =======, and >>>>>>> markers. Your job is to decide which version (or a combination) is correct, remove the markers, and commit the resolution. Use our Diff Tool to compare conflicting versions side by side before resolving.
Pull Requests and Code Review
A pull request (PR) or merge request (MR) is a proposal to merge one branch into another. It's the primary mechanism for code review in team workflows. A good PR is small enough to review in one sitting (under 400 lines changed is a reasonable target), has a clear description of what it does and why, and includes evidence that it works (tests, screenshots).
Git Workflows
Git Flow uses long-lived branches (main, develop, release, hotfix, feature). Rigorous but complex. Best for projects with scheduled releases. GitHub Flow is simpler: branch from main, open a PR, merge to main, deploy immediately. Good for continuous deployment. Trunk-based development is the most streamlined: everyone commits directly to main (or uses very short-lived feature branches), with feature flags controlling what's visible in production.
Essential Git Commands
The commands you'll use daily: git status, git add -p (stage interactively), git commit -m "message", git push, git pull --rebase, git log --oneline --graph, git stash / git stash pop, git diff main, git reset --soft HEAD~1 (undo last commit, keep changes staged).