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 cleanStep 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/nameStep 5: Push your branch to the remote
Push your branch and set the upstream tracking reference.
- (extra) before pushing, I may do
git pulljust to make sure that what added does not conflict with the “master” content
# git pull origin master
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
At this point if I look at GitHub, I will see that the “feature/name had recent push/es”
Step 7 (optional): Merge latest master into your feature branch
Switch back to your feature branch
git checkout feature/nameMERGE OR REBASE to avoid conflicts when the PR is reviewed or merged.
-
mergekeeps the commit history of the branch ✅
-
-
rebaserewrites 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/nameStep 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+ [If the reviewer is someone else, he could `git pull origin feature/name` to copy the branch and check it out]
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"
git pull origin master # once again to ensure nothing breaks
# update the pull request
git push origin feature/nameStep 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 masterVerify branches
git branch -vv # * wkg_br abc1234 [origin/wkg_br] your commit message here
git log --graph --all --oneline --decorateStep 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