Skip to content

Instantly share code, notes, and snippets.

@azpoint
Last active April 30, 2025 16:00
Show Gist options
  • Save azpoint/29a7a77410c52ba81156590e0798e6ca to your computer and use it in GitHub Desktop.
Save azpoint/29a7a77410c52ba81156590e0798e6ca to your computer and use it in GitHub Desktop.

🌳 Trunk-Based Development with Git: Step-by-Step (Annotated for Solo Developers)

This markdown document walks you through trunk-based development using Git, explaining each command in detail. Comments include tips and notes for solo developers, who can often streamline parts of the process.


🧭 Start from the Trunk

git checkout main

➡️ Switch to the main branch — this is your trunk, the central integration branch.

git pull origin main

➡️ Update your local main branch with the latest changes from the remote repository (origin).

Solo Developer Note: Even when working alone, always pull the latest in case you've pushed from another machine or workflow.


🌿 Create a Feature Branch

git checkout -b feature/your-feature

➡️ Create and switch to a new branch named feature/your-feature. The -b flag combines branch creation and checkout.

Solo Developer Tip: Use short, meaningful names like fix/login-bug or feat/add-navbar.


🛠️ Stage and Commit Changes

git add .

➡️ Stage all changes in the working directory.

git commit -m "WIP: partial work on feature"

➡️ Commit staged changes with a message. WIP = Work In Progress.


☁️ Push Work to Remote (In Progress)

git push origin feature/your-feature

➡️ Pushes your local branch (feature/your-feature) to the remote repository (origin).
This is useful for backup, sharing code with teammates, or opening a Pull Request.

Solo Developer Tip: Even if you're working alone, pushing periodically gives you a backup and enables syncing across machines.


🔄 Rebase with Latest Trunk (Keep History Clean)

Before merging into main, ensure your branch is based on the latest code:

git fetch origin

➡️ Updates your local view of the remote repository, fetching all new commits from origin.

git rebase origin/main

➡️ Reapplies your changes on top of the latest origin/main.
This helps prevent merge conflicts and maintains a linear commit history.

Solo Developer Tip: Rebasing regularly avoids painful merges later — even if you're the only contributor.


⚠️ Resolve Rebase Conflicts (if any)

git add .

➡️ After resolving conflicts, use git add to stage the fixed files.

git rebase --continue

➡️ Continue the rebase process after conflict resolution.


✅ Run Tests

npm test

➡️ Run your project's test suite. Replace with your own command if different.

Solo Developer Tip: Always test before merging, even if no one is reviewing your code.


☁️ Push Finalized Feature Branch

git push origin feature/your-feature

➡️ Pushes the rebased (and now clean) version of your feature branch to the remote repository.
This can now be reviewed and merged, or used in a CI pipeline.


🔀 Merge Feature into Trunk

git checkout main

➡️ Switch back to the main branch.

git pull origin main

➡️ Ensure local main is up to date before merging.

git merge feature/your-feature --no-ff

➡️ Merge your feature into main. The --no-ff flag forces a merge commit for traceability.

Solo Developer Tip: This step is still useful — keeping merge commits helps visualize history later.


☁️ Push Merged Trunk

git push origin main

➡️ Push the updated main branch to the remote.


🧹 Clean Up Branches

git branch -d feature/your-feature

➡️ Delete the local feature branch.

git push origin --delete feature/your-feature

➡️ Delete the remote feature branch.


🔁 Summary Flow

checkout main ➜ pull ➜ checkout -b feature ➜ work & commit ➜ push ➜ rebase ➜ test ➜ push again ➜ merge ➜ delete branch

🔒 Solo Developer Reminder: Even when working solo, following this flow keeps your history clean, ensures backup, and simplifies collaboration or CI/CD setup later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment