π Introduction
In corporate environments, collaboration, code quality, and traceability are crucial. Thatβs why teams adopt structured Git workflows β most commonly the feature branching model.
Whether you're onboarding or refreshing your Git skills, this guide walks you through the entire lifecycle of a feature branch: from creation to merging via pull request (PR).
π Why Use Feature Branches?
Feature branches let developers:
- Work on isolated features safely
- Keep
main
ordevelop
stable - Enable clean code reviews and testing
- Trace what feature/bug each commit belongs to
π Standard Workflow Overview
Here's a high-level view:
- β
Start from the latest
main
(ordevelop
) - πΏ Create a feature branch
- π Make code changes and commit
- β¬οΈ Push the feature branch to remote
- π© Create a Pull Request (PR)
- π Collaborate, review, and approve
- π Merge the PR
- π§Ή Clean up (delete feature branch)
π» Step-by-Step Guide with Git Commands
β 1. Sync with Main Branch
Always start with the latest base code to avoid conflicts later.
git checkout main
git pull origin main
Use
develop
instead ofmain
if your company follows Git Flow.
πΏ 2. Create a Feature Branch
git checkout -b feature/your-feature-name
π§ Tip: Use consistent naming like:
feature/add-login-page
bugfix/fix-header-glitch
hotfix/rollback-v2
π 3. Make Changes and Commit
After coding:
git add . # or specific files
git commit -m "Add login API integration"
π‘ Best Practices:
- Write meaningful commit messages
- Commit often and logically
- Donβt commit secrets or env files
β¬οΈ 4. Push to Remote
git push origin feature/your-feature-name
π© 5. Create a Pull Request (PR)
Now open your Git platform (e.g., GitHub, GitLab, Bitbucket):
- Choose the base branch (
main
ordevelop
) - Select your feature branch
- Write a descriptive title and summary
- Assign reviewers
π― Include:
- What was done
- Screenshots (if UI-related)
- Test instructions
π 6. Collaborate on Review
Your teammates may suggest improvements. Make those changes, then:
git add .
git commit -m "Fix: Updated validation based on review"
git push
π‘ PRs may trigger:
- Code quality checks (Sonar, Lint)
- Unit tests / integration tests
- CI/CD pipelines
π 7. Merge the PR
Once approved and tests pass, merge it using the UI.
π§ Depending on policy, use:
- Merge commit β preserves full history
- Squash merge β combines all commits into one
- Rebase & merge β keeps linear history
π§Ή 8. Clean Up
Post-merge, delete the feature branch:
git branch -d feature/your-feature-name # Local
git push origin --delete feature/your-feature-name # Remote
π§ Additional Tips
π§Ό Keeping Feature Branch Updated
If the main branch moves forward, rebase your feature:
git fetch origin
git rebase origin/main # or origin/develop
If conflicts occur:
# fix conflicts in files
git add .
git rebase --continue
π Summary
Step | Action | Git Command |
---|---|---|
1 | Sync main | git pull origin main |
2 | Create branch | git checkout -b feature/xyz |
3 | Commit code |
git add . + git commit
|
4 | Push branch | git push origin feature/xyz |
5 | Open PR | (Via GitHub/GitLab UI) |
6 | Review + Fix |
git commit + git push
|
7 | Merge PR | (Via UI) |
8 | Delete branch |
git branch -d + git push origin --delete
|
π Final Thoughts
This workflow ensures clean collaboration, quality assurance, and streamlined delivery. Following it helps:
- Reduce merge conflicts
- Improve review efficiency
- Maintain a clean Git history
π§ Use this blog as a reference during daily development or onboarding. If your team uses Git Flow or trunk-based development, the core ideas still apply with minor variations.
Top comments (0)