Skip to content
Careersbeginner

What are Git workflows?

Updated Nov 30, 20263 min readBased on official documentation
What are Git workflows?

In short

A Git workflow is an agreed way a team uses branches, merges and releases to manage code changes. It sets rules for where work happens, how changes move between branches, and how releases are made. Git itself does not force one workflow, so teams choose the rules that suit them.

Why teams need a workflow

Git lets many people change the same project at the same time. Without shared rules, those changes can pile up in a confusing history. A Git workflow is a set of habits that tells the team where to commit, how to combine changes, and how to publish releases.

The guidance below comes from the way the Git project itself is managed. It is a good example of a careful, branch-based approach that you can adapt to your own team.

Merging and cherry-picking

Git has two main ways to bring a change from one branch to another. A merge combines the whole history of one branch into another. Cherry-picking copies a single commit to a different branch.

Merges work at the branch level. One merge can carry changes from one commit or from a thousand commits with about the same effort. That makes merges a better fit for large teams. A merge commit also records that all changes from its parent branches are now included, which makes the history easier to read.

Cherry-picking works at the commit level, so it is useful now and then, but it should not be the main tool. Merges do require more care in how branches are managed, and the rest of the workflow is built around that.

Integration branches and graduation

An integration branch is a long-lived branch that collects work before it is released. Changes start on an unstable branch and move toward a stable one as they prove themselves. This movement is often called graduation.

The Git project uses four such branches. One tracks fixes for the last stable release, one tracks the next release, one is used for testing topics before they reach the release branch, and one holds work that is not yet ready for testing. Each branch usually contains everything in the branch above it.

A key rule follows from this: fix a bug on the oldest branch that still needs it, then merge upward into the newer branches. Merging downward would pull unfinished work into stable code, so it is avoided.

Topic branches

A topic branch is a short-lived branch for one feature or bug fix. You create it from the oldest integration branch you plan to merge into. Work stays isolated there until it is ready.

Topic branches help in several ways. Bad commits can be dropped or fixed without touching the main line. Parallel work does not mix together. When the topic is ready, you merge it into the integration branch. If the topic changes later, you merge again.

There is one caveat. A topic that has already been merged somewhere should not be rebased, because rebasing rewrites its history and confuses anyone who has used it. Rebasing is only safe before the branch is shared or merged.

Keep merges deliberate

It can be tempting to merge the main branch into your topic every day to stay current. The Git guidance warns against this. Frequent small merges clutter the history, and it becomes hard to tell what a merge changed.

Merge downstream only when you have a good reason, such as an upstream API change that affects your work or a branch that no longer merges cleanly.

A throw-away integration branch can help when you want to test several topics together. Merge them into a temporary branch, test the result, and delete it afterward. Nobody should build real work on top of that temporary branch.

Releases and maintenance

A feature release is made from the branch that collects the next release. Before tagging, check that this branch contains every fix from the maintenance branch. A command such as git log master..maint should list no commits when everything is in place. A release is marked with a tag, which is a named pointer to one commit, and the tag is then pushed to a shared server.

After a release, the maintenance branch is fast-forwarded to the new release so that later fixes continue from it. If you still support the previous release, copy the maintenance branch to a new branch named for that older version first.

If you want a tidier history, you can rebuild the next-release testing branch from the new release. Do this only if you announce it, because others may have based work on the old version.

Learn more

The full guide describes these rules in more detail, including how distributed teams publish their work. Read the official Git workflows documentation at https://git-scm.com/docs/gitworkflows for the complete picture.

FAQ

Is there one correct Git workflow?

No. Git does not enforce a single workflow. Teams pick rules that fit how many people they have and how often they release.

What is the difference between merging and cherry-picking?

A merge brings in all the changes from a branch at once. Cherry-picking copies one commit at a time, which is handy for a single fix but harder to manage at scale.

What is a topic branch?

It is a short-lived branch created for one feature or bug fix. You keep work there until it is ready, then merge it into a shared branch.

Why should I not rebase a branch that was already merged?

Rebasing rewrites commit history. If others already merged the branch, their copies no longer match yours, which causes confusion and extra work.

Sources

This page is based on the official documentation below. Read it for full detail.

Git workflows — official documentation ↗
blozhikDeveloper news from across the web, explained. Every story links to its original sources.