What you can do after this lesson
You will be able to read a team's description of how it works with Git, compare the three most common styles, and set up a sensible one for a small project. Git gives you branches and merges; it does not tell you how to use them. A workflow is the team agreement on that. The aims are always the same: keep the main line working, let people work in parallel, and make releases predictable.
These workflows are widely described by GitHub, by the Pro Git book and by the wider industry, but they are conventions, not standards, and names vary between teams. Where a claim is practitioner opinion rather than documentation, we say so.
Feature-branch workflow
The simplest shared idea: never work directly on main. Each task gets its own branch, named for what it does. When finished, it is merged back.
git switch -c feature/login
git add . && git commit -m "Add login page"
git push -u origin feature/loginTo /home/you/w/origin.git
* [new branch] feature/login -> feature/login
branch 'feature/login' set up to track 'origin/feature/login'.Then merge, either by pull request on a hosting service or locally:
git switch main
git merge --no-ff feature/login -m "Merge feature/login"
git branch --mergedMerge made by the 'ort' strategy.
login.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 login.txt
feature/login
* maingit branch --merged lists branches fully included in the current one, which are safe to delete. git branch --no-merged lists the ones that still hold unmerged work. Your hashes will differ.
GitHub flow
GitHub describes a lightweight version of this and calls it GitHub flow. The steps, as GitHub's documentation lays them out:
- Create a branch from
mainwith a descriptive name. - Make commits.
- Open a pull request.
- Discuss and review, pushing further commits as needed.
- Merge into
main. - Delete the branch.
The idea is that main is always deployable and every change reaches it through a pull request. It suits teams that release often, for instance websites that deploy after every merge. It has no long-lived branches apart from main, which keeps things understandable for beginners. Protection rules on main (require a pull request, require checks to pass) back the agreement up with enforcement.
Trunk-based development
In trunk-based development, everyone integrates into one branch, the "trunk" (normally main), very frequently. Branches, if used at all, last hours or a day or two. Instead of keeping an unfinished feature on a long branch, developers merge small pieces and hide unfinished behaviour behind a switch in the code called a feature flag.
The argument for it, which is the experience of many practitioners rather than a hard fact, is that frequent merges keep differences small so conflicts stay small, and that it works well with automated tests that run on every change. The cost is that it needs good automated testing and team discipline; broken code on the trunk affects everyone at once. It is common in larger teams that deploy continuously.
The difference from GitHub flow is mainly one of degree: how long branches live and how often you integrate. Many teams sit in between.
Comparing them
| Feature branches | GitHub flow | Trunk-based | |
|---|---|---|---|
| Branch lifetime | days to weeks | hours to days | hours, or none |
| Review | usually by pull request | pull request | pull request or pairing, quick |
| Main branch | stable | always deployable | always deployable |
| Needs | agreement | agreement and protection rules | strong automated tests, feature flags |
None is universally best. A solo project can use plain commits on main. A team of five with a website probably wants GitHub flow. A large team deploying many times a day may choose trunk-based.
Release tags and release branches
Whatever workflow you use, you will want to mark releases. A tag names one exact commit forever. Create an annotated tag and push it with the branch:
git tag -a v1.0.0 -m "Release 1.0.0"
git push --follow-tags origin mainTo /home/you/w/origin.git
f05fe64..4f485fe main -> main
* [new tag] v1.0.0 -> v1.0.0--follow-tags pushes annotated tags that point at the commits being pushed. Tags are covered in depth in lesson 23. A common naming scheme is semantic versioning, where v1.4.2 means major 1, minor 4, patch 2; it is a convention many projects adopt, not part of Git.
A release branch is optional. If you must keep supporting version 1.0 while main moves toward 2.0, create release/1.0 from the tag:
git switch -c release/1.0 v1.0.0Bug fixes for 1.0 go there, and can be copied to main with cherry-pick (lesson 24). Teams that ship only the latest version rarely need release branches.
Choosing and writing it down
A good rule: choose the simplest workflow that your team can follow without thinking. Then write it in CONTRIBUTING.md or a team page: branch naming, how reviews work, which merge style, how releases are tagged. Unwritten workflows drift, and new members guess.
Common mistakes
- Long-lived feature branches. The longer they live, the harder they are to merge.
- Committing directly to
mainon a team that expects pull requests. Protection rules prevent it; follow them. - Using different merge styles randomly. Agree on one.
- Tagging without pushing. A local tag is invisible until you push it.
- Copying a big-team workflow for a tiny project. Process should fit the size of the team.
Exercise
- Describe, in two sentences each, how you would run a personal blog repository and a five-person project with Git.
- In a practice repository, create
feature/search, commit on it, merge it with--no-ff, and list merged branches. - Tag the result
v0.1.0with a message and push the tag to a local bare remote.
Show one possible answer
A personal blog can simply commit to main with a clear message each time, using a branch only for risky redesigns. A five-person project suits GitHub flow: branch per change, pull request with one review, merge into a protected main, tag releases.
git switch -c feature/search
echo s > search.txt && git add . && git commit -m "Add search page"
git switch main
git merge --no-ff feature/search -m "Merge feature/search"
git branch --merged
git tag -a v0.1.0 -m "First release"
git push --follow-tags origin mainNext: Working in a team with Git: habits that prevent trouble.
Key points
- A workflow is an agreement about how branches, reviews and releases fit together; Git does not enforce one.
- In feature-branch and GitHub flow, every change lives on a short branch and is merged into main through a pull request.
- Trunk-based development keeps branches very short or avoids them, merging to main many times a day with automated checks.
- Release tags mark exact versions; a release branch is optional and used when several versions need support.
- Pick the simplest workflow your team can follow consistently, and write it down.