Here’s a clear, logical map of how branches and the flow actually work, matched as closely as possible to the three-stage process you described.
A branch is just a movable pointer to a series of commits.
main(ormaster) is simply the conventional name for the primary branch. It is not special in the Git software itself — teams decide what it means.- You can create as many other branches as you like (
dev,staging,prod,feature/xyz,hotfix/123, etc.). - Each branch can live on your local machine and on the remote (GitHub). They stay independent until someone deliberately merges them.
You want this sequence:
- Local / team development work → changes stay isolated
- Integration / work branch → changes are reviewed, tested, and consolidated
- Production / release branch → only fully approved code goes here and triggers deployment
Here is the cleanest way to implement that:
| Stage | Typical branch name(s) | What happens here | Who can merge into it | What “moves” the code |
|---|---|---|---|---|
| 1. Development | feature/*, dev, or personal branches |
You and teammates write code, commit, push freely | Anyone with write access can push | git push |
| 2. Integration / Testing | main (or develop / staging) |
Pull Requests are reviewed, tests run, conflicts fixed | Only authorized people (or protected branch rules) | Pull Request + merge |
| 3. Production / Release | prod / release / main (if you use a single main) |
Final verified code; deployment scripts watch this branch | Very few people (or only CI) | Pull Request or automated promotion |
Option A – Simple & common (recommended for most teams)
feature branches → main → production (or release)
- Developers create short-lived branches from
main(or fromdev). - They push their branch and open a Pull Request (PR) into
main. - Authorized reviewers approve → merge into
main. - After tests pass on
main, another PR (or automated process) promotes the code into aprod/releasebranch. - Your server watches the
prodbranch and deploys when it changes.
Option B – Classic Git-Flow style
feature/* → develop → release/* → main (production)
develop= your “work / integration” branchmain= productionrelease/*branches are temporary stabilisation branches
| Term | What it really does | When you use it in your 3-stage flow |
|---|---|---|
| clone | Downloads the entire remote repository to your machine for the first time | Once, when you start working on a project |
| commit | Saves a snapshot of your changes on your current branch (still only local until you push) | Continuously while developing |
| push | Uploads your local commits to the matching branch on the remote | After you finish a piece of work on a feature branch |
| pull | Fetches remote changes and merges them into your current local branch | Before you start new work, or to stay up-to-date |
| fetch | Downloads remote changes but does not merge them yet | Safer alternative to pull when you want to inspect first |
| branch | Creates a new pointer so you can work without touching other people’s code | At the start of every feature or fix |
| merge | Combines the history of one branch into another | Usually done via a Pull Request (not by hand) |
| Pull Request (PR) | A formal request on GitHub: “Please review and merge my branch into this other branch” | The only way code should move from stage 1 → stage 2, and stage 2 → stage 3 |
| protected branch | GitHub setting that blocks direct pushes and requires PRs + reviews + tests | Put this on main and especially on prod |
-
Start work (Stage 1)
git checkout main git pull # get latest git checkout -b feature/my-change # write code, commit, push git push -u origin feature/my-change
-
Move to integration (Stage 2)
- Open a Pull Request on GitHub:
feature/my-change→main - Reviewers approve, CI tests run
- Authorized person clicks Merge
→ Code is now on the work/integration branch (main)
- Open a Pull Request on GitHub:
-
Move to production (Stage 3)
- Open another PR:
main→prod(or use an automated promotion) - Extra checks / approvals
- Merge
→ Server detects the change onprodand runs your deploy scripts
- Open another PR:
- Protect the important branches (
mainandprod) in GitHub settings:- Require Pull Request reviews
- Require status checks (tests) to pass
- Restrict who can push / merge
- Never let people push directly to
mainorprod. - Feature branches can be pushed freely; only the merge into the protected branches needs authorization.
Local machine Remote GitHub
───────────── ─────────────
feature/xyz ──push──► feature/xyz
│
│ Pull Request + Review + Tests
▼
main (integration / work branch)
│
│ Pull Request (or auto-promote)
▼
prod (final release branch)
│
└──► Server watches this → builds & deploys