🌙
☀️ Dark
PART 26

Git & Professional Workflow

Rebase, branches, PRs, conventional commits.

Intermediate 45 min read
Volume 26 - GIT & PROFESSIONAL WORKFLOW

Revision Sheet

  • Commit: Immutable snapshot of the repository.
  • Branch: Movable pointer to a commit.
  • Merge: Combining branch histories (preserves history, messy graph).
  • Rebase: Replaying commits onto a new base (rewrites history, clean linear graph).
  • HEAD: Where you currently are.
  • Reflog: The safety net recording all HEAD movements.
  • Conventional Commits: Structured messages (feat, fix, chore) for automated SemVer.

Connections

Git is the foundation of CI/CD (Continuous Integration / Continuous Deployment). Every push to a repository acts as a trigger for automated pipelines (like GitHub Actions or Jenkins) to build, test, and deploy the code, bridging the gap between local development and cloud infrastructure.

🏠 Curriculum NextVolume 2

Mini Project (20-30 min)

▶ View Solution

Simulate a hotfix workflow:

  1. Create a main branch with a file app.js containing a "bug" (e.g., const tax = 0;).
  2. Create a develop branch and add some new features.
  3. Oh no, production is broken! Create a hotfix branch directly off main.
  4. Fix the bug (const tax = 0.2;) and commit.
  5. Merge hotfix into main and tag it v1.0.1.
  6. Merge hotfix into develop so the next release also has the fix.

Bigger Project (1-2 hours)

Apply all concepts from this volume to build a comprehensive feature.

▶ View Solution
typescript
// Example project code here

Interview Questions

Easy: What is the difference between git pull and git fetch?

git fetch downloads the latest history from the remote tracking branches but does not touch your local working files. git pull runs a fetch, and then immediately runs a merge to integrate the fetched changes into your current branch.

Medium: Explain the difference between merge and rebase.

Both integrate changes from one branch to another. Merge creates a new commit that ties the two histories together, preserving the exact chronological history but creating a non-linear graph. Rebase rewrites your branch's commits as if they were based on the latest tip of the target branch, resulting in a clean, linear history, but it changes the commit hashes.

Hard: How do you find which commit introduced a bug?

Using git bisect. You tell Git a "good" commit (where it worked) and a "bad" commit (where it's broken). Git uses binary search, checking out commits in the middle for you to test, rapidly narrowing down the exact commit that introduced the issue in O(log N) time.

Senior: Describe how you would design a CI/CD branching model for a SaaS platform with 50 developers doing continuous deployment.

I would advocate for GitHub Flow or Trunk-based development. A long-lived develop branch (GitFlow) causes integration bottlenecks. We would mandate that main is always deployable. Engineers work on short-lived feature branches, squash-merge via PRs after mandatory automated tests and code reviews pass. Any unfinished features merged to main would be wrapped in application-level Feature Flags. Hotfixes are just fast-tracked PRs to main.