Git Workflows: Feature Branches, Pull Requests, GitHub Flow, Gitflow, Forking and Trunk-Based
How teams organize work with Git: the centralized workflow, feature branches and pull requests, GitHub flow, Gitflow with develop, release and hotfix branches, release branches for maintained versions, trunk-based development with feature flags, the forking workflow, and how to choose.
kvi5hnuCode Sprout team member8 min readOn this page
Git doesn't prescribe how a team should use branches. A workflow is a team's agreement: which branches exist, where new work starts, how it's reviewed, and how it reaches production. This article describes the common workflows, what each is good at, and how to pick one. They differ less than their names suggest: almost all use short-lived feature branches and pull requests, and differ in how releases are handled.
Centralized: everyone commits to main
The simplest workflow, familiar from older systems like Subversion: one shared repository, one branch, and everyone commits to main and pushes. Before pushing, each person pulls, ideally with --rebase, to integrate the others' work (article 19).
It works for one person, or a very small team on a small project. It breaks down as the team grows: unfinished work lands on main, there's no place for review, and a broken commit blocks everyone.
Feature branches and pull requests
The basis of nearly every modern workflow: all work happens on a branch, and reaches main through a pull request (GitHub, Bitbucket) or merge request (GitLab):
- Update
mainand create a branch:git switch -c feature/lake-page origin/main. - Commit, and push the branch regularly:
git push -u origin feature/lake-page. - Open a pull request: a request to merge your branch into
main, with a place for discussion, review comments and automated checks (CI). - Address review feedback with more commits, or rewrite the branch and force push with lease (article 20).
- When it's approved and the checks pass, merge it, with a merge commit, squash or rebase (article 12), and delete the branch.
git init -q --bare server.git
git clone -q server.git sam 2>/dev/null; cd sam
echo "# Trail guide" > README.md; git add .; git commit -q -m "Start project"; git push -q origin main
cd ..; git clone -q server.git ana 2>/dev/null
cd ana # Ana: a branch for the lake page
git switch -q -c feature/lake-page origin/main
echo "Lake path: 5 km" > lake.txt; git add .
git commit -q -m "Add lake page" --author="Ana Diaz <ana@example.com>"
git push -q -u origin feature/lake-page
cd ../sam # Sam: reviews and merges the "pull request"
git fetch -q
echo "=== what the pull request would show"
git log --oneline main..origin/feature/lake-page
git diff --stat main...origin/feature/lake-page
git merge -q --no-ff origin/feature/lake-page -m "Merge pull request: lake page"
git push -q origin main
git push -q origin --delete feature/lake-page
echo "=== main after the merge"
git log --oneline --graph
=== what the pull request would show
3d9f814 Add lake page
lake.txt | 1 +
1 file changed, 1 insertion(+)
=== main after the merge
* 4ff0790 Merge pull request: lake page
|\
| * 3d9f814 Add lake page
|/
* 7fb62a0 Start project
Pull requests are a hosting service feature, not part of Git itself, but underneath they're exactly this: a branch, a comparison with main...branch, and a merge. The benefits: main only receives reviewed work, CI tests each change before it lands, and the discussion is kept with the change.
GitHub flow: main is always deployable
GitHub flow is the feature branch workflow plus one rule: anything on main can be deployed, and is deployed soon after each merge. There's one long-lived branch, main, and short-lived branches for every change.

It suits web applications and services that deploy continuously, where only one version is in production at a time. Its requirements are good automated tests and the ability to deploy, and roll back, easily. GitLab flow is a close variant that adds environment branches, such as production or staging, when deployment can't happen on every merge.
Gitflow: develop, release and hotfix branches
Gitflow has two long-lived branches and three kinds of short-lived ones:
| Branch | Purpose | Starts from | Merges into |
|---|---|---|---|
main | released versions only, each tagged | ||
develop | integration of finished features for the next release | ||
feature/* | one feature | develop | develop |
release/* | preparing a release: version numbers, final fixes | develop | main (tagged) and develop |
hotfix/* | an urgent fix to the released version | main | main (tagged) and develop |
git init -q trail-guide && cd trail-guide
echo "# Trail guide" > README.md; git add .; git commit -q -m "Start project"
git switch -q -c develop
git switch -q -c feature/lake develop
echo "Lake" > lake.txt; git add .; git commit -q -m "Add lake page"
git switch -q develop; git merge -q --no-ff feature/lake -m "Merge feature/lake"; git branch -q -d feature/lake
git switch -q -c release/1.0 develop # prepare the release
echo "1.0" > VERSION; git add .; git commit -q -m "Set version 1.0"
git switch -q main; git merge -q --no-ff release/1.0 -m "Release 1.0"; git tag -a v1.0 -m "Version 1.0"
git switch -q develop; git merge -q --no-ff release/1.0 -m "Merge release/1.0 into develop"; git branch -q -d release/1.0
git switch -q -c hotfix/1.0.1 main # urgent fix to the release
echo "1.0.1" > VERSION; git commit -q -am "Fix lake distance, version 1.0.1"
git switch -q main; git merge -q --no-ff hotfix/1.0.1 -m "Hotfix 1.0.1"; git tag -a v1.0.1 -m "Version 1.0.1"
git switch -q develop; git merge -q --no-ff hotfix/1.0.1 -m "Merge hotfix/1.0.1 into develop"; git branch -q -d hotfix/1.0.1
echo "=== main: one commit per release, each tagged"
git log --first-parent --format='%h %s%d' --decorate main
echo "=== develop: features, plus the release and hotfix merged back"
git log --first-parent --format='%h %s%d' --decorate develop
=== main: one commit per release, each tagged
7a3d4bb Hotfix 1.0.1 (tag: v1.0.1, main)
725d71f Release 1.0 (tag: v1.0)
7fb62a0 Start project
=== develop: features, plus the release and hotfix merged back
483a4c8 Merge hotfix/1.0.1 into develop (HEAD -> develop)
359b5a1 Merge release/1.0 into develop
ca8cfff Merge feature/lake
7fb62a0 Start project
--first-parent follows each branch's own line of merges, so the full graph, which is a tangle of merges in both directions, isn't needed to see what happened. Gitflow suits software released in numbered versions on a schedule, such as installed applications or libraries, where a release needs time to stabilize while new work continues. For continuously deployed services, its overhead is usually not worth it: two long-lived branches to keep in sync, merges in both directions, and features waiting on develop before reaching users. Its original author has since recommended simpler workflows for such projects. The git flow extension command automates the steps above, but it's optional: they're ordinary branches and merges.
Release branches for maintained versions
Projects that support several versions at once, such as a library with 2.x and 3.x users, often combine trunk development with release branches: work happens on main, a branch like release/2.4 is cut when 2.4 ships, and fixes are made on main and cherry-picked to the release branches that need them, with git cherry-pick -x recording the source (article 16). Releases are tagged on their branch.
Trunk-based development
In trunk-based development, everyone integrates into main (the "trunk") at least daily. Branches, if used, live for hours or a day or two, and are merged after quick review. Unfinished features are merged anyway, hidden behind feature flags, configuration switches that turn them on for users only when ready.
The benefits are few merge conflicts, since nobody's branch drifts far from main, fast feedback, and always-releasable code. It needs strong automated testing, fast CI, and the discipline to keep changes small. Many large engineering organizations work this way.
The forking workflow
In open source, contributors usually can't push to the project's repository. Instead each contributor forks it, creating their own copy on the hosting service:
- Fork the project, then clone your fork: it becomes
origin. - Add the original as
upstream:git remote add upstream <original-url>(article 17). - Create a branch from
upstream/main, commit, and push the branch toorigin, your fork. - Open a pull request from your fork's branch to the original project's
main. - Keep up to date with
git fetch upstreamandgit rebase upstream/main.
Maintainers review and merge as usual. The forking workflow is the feature branch workflow with the branches living in different repositories.
Choosing a workflow
| Situation | Good fit |
|---|---|
| Solo project, or a tiny team | centralized or simple feature branches |
| Web app or service deployed continuously | GitHub flow, or trunk-based with feature flags |
| Scheduled, numbered releases | Gitflow, or main plus release branches |
| Several supported versions | main plus release branches, with cherry-picked fixes |
| Open source with outside contributors | forking workflow |
Whatever the workflow, the same practices make it work: short-lived branches, frequent integration with main, small reviewable pull requests, automated tests on every pull request, protected main branches, and agreed conventions for branch names and commit messages (article 52).
What's current
- Hosting services support branch protection and rulesets: required reviews, required status checks, linear history, and no force pushes to
main. - Merge queues (GitHub, GitLab merge trains) test each pull request against the latest
mainplus everything ahead of it in the queue before merging, so a busymainnever breaks from two changes that were each fine alone. - Stacked pull requests, chains of small dependent branches, are increasingly common.
git rebase --update-refskeeps such stacks consistent (article 14).
Common questions
What's the difference between a pull request and git pull?
A pull request is a hosting service feature: a request to merge one branch into another, with review and discussion. git pull is a Git command that fetches and integrates the upstream into your current branch. The name comes from asking maintainers to pull your branch.
Is Gitflow outdated? Not outdated, but often unnecessary. It fits versioned releases that need stabilization. For services deployed continuously, GitHub flow or trunk-based development is simpler and usually better.
How long should a feature branch live?
As short as possible: days, not weeks. Long-lived branches drift from main and produce painful merges. Split big features into smaller pull requests, using feature flags if needed.
Should we merge, squash or rebase pull requests?
Any can work. Agree on one per repository. Squash keeps main to one commit per pull request, merge commits keep full history, and rebase keeps individual commits on a straight line (article 12).
Summary
- A workflow is a team agreement about branches, review and releases.
- Feature branches and pull requests underlie almost every workflow: branch from
main, push, review, merge, delete. - GitHub flow: one long-lived
main, always deployable, short branches merged through pull requests. - Gitflow:
mainfor releases anddevelopfor integration, with feature, release and hotfix branches. It suits scheduled, versioned releases. - Release branches plus cherry-picked fixes support several versions. Trunk-based development integrates into
maindaily, using feature flags. - The forking workflow uses personal forks,
originfor your fork andupstreamfor the original.
Practice questions
In Gitflow, a critical bug is found in released version 1.4.0. Where does the fix branch start, and where is it merged?
Answer
A hotfix/1.4.1 branch starts from main, which holds the released code. After the fix, it's merged into main, tagged v1.4.1, and also merged into develop, so the next release includes the fix.
Your team deploys a web app several times a day and finds Gitflow's develop branch slows things down. What would you suggest, and what does it need?
Answer
GitHub flow or trunk-based development: one long-lived main that's always deployable, short-lived branches merged through reviewed pull requests, and deployment after each merge. It needs reliable automated tests on every pull request, easy deployment and rollback, and, for unfinished features, feature flags.
You forked an open-source project and cloned your fork. How do you keep your branch up to date with the original project?
Answer
Add the original as a second remote and rebase onto it:
git remote add upstream https://github.com/original/project.git
git fetch upstream
git rebase upstream/main # on your feature branch
git push --force-with-lease # update your fork's branch, if already pushed
Previous: Connecting to Remotes: HTTPS Tokens, Credential Helpers, SSH Keys and Proxies
Next: Tidying Up: Pruning Remote-Tracking Branches and Deleting Merged and Gone Branches

More in Git Course
Quiz: Git Delicate Details
Twenty-five questions on Git's subtle corners: what commit -a and stash leave out, empty folders, ignore patterns and negation, HEAD~ versus HEAD^, ours and theirs in a rebase, tags that don't move or don't push, describe, merge reverts, diff exit codes, stash conflicts and more.
Quiz: Git Interview Questions
Thirty Git questions of the kind asked in developer interviews: Git versus GitHub, the staging area, merge versus rebase, fetch versus pull, reset, revert and restore, detached HEAD, conflicts, force pushing, stash, cherry-pick, reflog, bisect, submodules, LFS and how commits are identified.
Quiz: Git Course Final Exam (All Parts)
The final exam for the Git course: thirty questions across all twelve parts, from the three areas and staging through branching, remotes, undoing, history investigation, configuration, tags, larger projects, patches, rewriting, internals and troubleshooting.
Quiz: Professional Git Practice (Git Part 12)
Sixteen questions on migrating to Git from Subversion, TFVC and Mercurial, team best practices for commits, branches and reviews, repository hygiene, and diagnosing and fixing the most common Git errors, with explanations.
Discussion
Sign in to ask a question or share what you learned.