Git Feature Branch Workflow
Intro
This workflow supports small-team collaboration using feature branches and GitHub pull requests. Based on:
—————– MASTER
Step 0: Clean your master
worktree
Make sure there are no uncommitted or unpushed changes in master
.
git status
# should output: nothing to commit, working tree clean
Step 1: Switch to master
and update it from origin
git checkout master
git pull origin master
—————– FEATURE BRANCH
Step 2: Create a new feature branch
Create a new branch based on the latest master
.
git checkout -b feature/name
(OR IF EXISTING) Switch to an existing feature branch:
git switch feature/name
(Make your changes)…
Step 3: Edit and commit changes
Stage and commit your changes regularly.
git add .
git commit -m "feat: update on x"
Step 4 (optional): Check differences from master
Useful for reviewing what the branch introduces.
git diff --color-words master..feature/name
Step 5: Push your branch to the remote
Push your branch and set the upstream tracking reference.
git push -u origin feature/name
—————– MASTER (optional
Step 6 (optional): Update local master
Switch back to master
to check if there have been any updates.
git checkout master
# (optional) update local repo with latest changes from remote
git pull origin master
—————– FEATURE BRANCH (optional
Step 7 (optional): Merge latest master
into your feature branch
Switch back to your feature branch
git checkout feature/name
MERGE OR REBASE to avoid conflicts when the PR is reviewed or merged.
-
merge
keeps the commit history of the branch ✅
-
-
rebase
rewrites commits, but keep the history of the branch clean ⚠️
-
Merge the latest changes from master
into your feature branch locally
git merge master
git push origin feature/name
Step 8 (optional): Review branch differences before PR
1/2 On GitHub: https://github.com/your-username/
/<master…feature/name> 2/2 In terminal:
git diff --color-words master..feature/name
Step 9: Create a pull request
You can do this either:
1/2 On GitHub: click 🔳 “Compare & pull request” or go to Pull Requests tab
2/2 In terminal:
gh pr create --base master --head feature/name --title "feat: upd..."
Step 10: Respond to code review (if needed)
…
If reviewers request changes:
git add .
git commit -m "fix: addressed review comments"
# update the pull request
git push origin feature/name
Step 11: Merge the pull request
On GitHub, choose your preferred merge method:
-
Squash and merge: one commit for the whole branch added to
master
- Rebase and merge: replays commits on top of base branch, (linear history)
- Merge commit: adds a merge commit preserving all commits as-is (full history)
Then confirm the merge.
—————– MASTER
Step 12: Pull the updated master
locally
After merging the PR:
git checkout master
git pull origin master
Verify branches
git branch -vv # * wkg_br abc1234 [origin/wkg_br] your commit message here
git log --graph --all --oneline --decorate
Step 13 (optional): Delete the feature branch
Delete your feature branch locally and remotely if it’s no longer needed.
git branch -d feature/name # local deletion
git push origin --delete feature/name # remote deletion