Mastering Git & GitHub: Branching Strategies and Open Source Workflows
Level up your professional version control skills: interactive rebasing, semantic commit messages, GitHub Actions CI, and resolving complex merge conflicts.
Beyond git add . and git push
Most beginners learn three commands in Git: git add, git commit, and git push. But when you join a software engineering team or contribute to major open-source repositories, uncurated commit histories and messy merges become major liabilities.
In this guide, we break down industrial Git habits that will set you apart.
1. Trunk-Based Development vs GitFlow
GitFlow (Legacy for release cycles)
- Complex branches:
feature/*,develop,release/*,hotfix/*,main. - Tends to create long-lived branches that result in painful merge conflicts.
Trunk-Based Development (Modern Industry Standard)
- Developers work in short-lived feature branches ($< 1-2$ days).
- Branches are merged into
mainfrequently through Pull Requests validated by automated CI tests. - Feature flags are used to hide uncompleted features in production.
2. Interactive Rebase: Clean History Before You Open a PR
Before submitting a Pull Request, squash your "wip", "fix typo", and "test" commits into clean, semantic units using interactive rebase:
# Rebase the last 4 commits
git rebase -i HEAD~4
In the editor:
pick e3f12a4 feat: add category filter to post manager
squash 9a2b1c3 fix typo in category schema
squash 4d5e6f7 format category files
3. Resolving Merge Conflicts with Confidence
When a conflict occurs:
- Don't panic: run
git statusto see the affected files. - Open your diff tool or IDE.
- Understand the markers:
<<<<<<< HEAD (Current branch)
const category = await getCategoryById(id);
=======
const category = await fetchCategoryWithCount(id);
>>>>>>> feature/category-counts (Incoming branch)
- Edit the file to the desired state, remove the conflict markers, and complete the rebase:
git add src/lib/category.ts
git rebase --continue
4. Semantic Commit Messages
Adopt the Conventional Commits specification:
feat: add bilingual support for post titlesfix: prevent null pointer on empty category descriptionrefactor: isolate database adapter to client singletondocs: update readme with environment setup guide
Good version control hygiene reflects professional discipline and makes peer code reviews effortless.