🇺🇸 English | ᴘᴛ Português | 🇧🇷 Português
⭐ If you enjoyed this repository, please give it a star
This repository is a visual, step-by-step guide for both beginners and professionals to understand and apply branching strategies in Git and GitHub. It includes clear definitions, workflow diagrams, and practical examples.
Term | Brief Description |
---|---|
branch / branches | An independent line of development. |
commit / commits | A snapshot of changes in the repository. |
pull request / PR | A proposal to merge one branch into another, with code review. |
merge / merges | The action of combining changes from different branches. |
main | The primary, stable branch (production). |
develop | The integration branch for new features. |
feature/ | Prefix for branches developing new features. |
bugfix/ | Prefix for branches fixing bugs during development. |
hotfix/ | Prefix for branches with critical production fixes. |
release/ | Prefix for branches preparing a new software release. |
experiment/ | Prefix for prototype and test branches without guaranteed merge. |
squash | Combines multiple commits into a single commit. |
rebase | Reapplies commits from one branch onto another, creating a linear history. |
-
Create a Branch
git switch -c feature/your-feature-name
-
Make Commits
git add . && git commit -m "Clear description of your change"
-
Push to GitHub
git push -u origin feature/your-feature-name
-
Open a Pull Request
- On GitHub, select your branch and click New Pull Request.
-
Review & Merge
-
After approval, merge and delete your branch:
git switch main && git pull git branch -d feature/nome-da-feature git push origin --delete feature/nome-da-feature
-
Each branch serves as an isolated workspace for your changes. Imagine your project history as the tree trunk (main), and each branch as a limb where you can work without impacting the trunk.
Prefixo | Exemplo | Propósito |
---|---|---|
main | main |
Production-ready code |
develop | develop |
Integration of new features |
feature/ | feature/login |
Development of a new feature |
bugfix/ | bugfix/erro-404 |
Bug fixes |
hotfix/ | hotfix/patch-1.0.1 |
Critical production fixes |
release/ | release/2.0.0 |
Release preparation |
experiment/ | experiment/a-b-test |
Experimental prototypes and tests |
- Always work from
main
. - Create a feature branch.
- Commit changes frequently.
- Push and open a PR.
- After approval, merge into
main
and deploy.
gitGraph
git checkout main
commit id:"v1.0.0 deploy"
branch feature/a
checkout feature/a
commit id:"Implementa A"
checkout main
merge feature/a
- main: production
- develop: continuous integration
- feature/*: branches created from
develop
- release/*: branches for release preparation
- hotfix/*: branches for urgent fixes
gitGraph
git checkout -b develop main
commit id:"Sprint Start"
branch feature/b
checkout feature/b
commit id:"Add Feature B"
checkout develop
merge feature/b
branch release/1.0.0
checkout release/1.0.0
commit id:"Finalize & Docs"
checkout main
merge release/1.0.0
tag v1.0.0
checkout develop
merge release/1.0.0
git switch -c prefix/branch-name
git fetch origin
# Rebase to sync with base
git rebase origin/main
git push -u origin prefix/branch-name
Note
Merge Options
- Merge Commit: preserves full commit history. Ideal for long-lived features.
- Squash and Merge: consolidates all commits into one. Use for a cleaner history.
- Rebase and Merge: creates a linear history. Best for atomic, well-defined commits.
- feature/: for new features.
- bugfix/: for fixes before release.
- hotfix/: for critical production patches.
- release/: for preparing a release.
- experiment/: for prototypes and tests.
- Use clear and consistent names.
- Make small and descriptive commits.
- Open detailed PRs with context.
- Protect key branches by requiring reviews.
- Delete merged branches to keep the repository tidy.
-
Clone the repository:
git clone https://github.com/your-username/Branches-Complete-Guide4-Repositories.git
-
Follow the Quickstart.
-
Try out the Workflows.
-
Contribute improvements via PR or Issue.
Made with ❤️ & Markdown by dev-ggomes with contributions from LeoSilva91