153

What is a git topic branch? Does it differ from an ordinary branch in some way? Are there any branches that are not topic branches?

Alex B
  • 24,678
  • 14
  • 64
  • 87
skiphoppy
  • 97,646
  • 72
  • 174
  • 218

4 Answers4

125

Topic branches are typically lightweight branches that you create locally and that have a name that is meaningful for you. They are where you might do work for a bug fix or feature (they're also called feature branches) that is expected to take some time to complete.

Another type of branch is the "remote branch" or "remote-tracking branch". This type of branch follows the development of somebody else's work and is stored in your own repository. You periodically update this branch (using git fetch) to track what is happening elsewhere. When you are ready to catch up with everybody else's changes, you would use git pull to both fetch and merge.

I have also seen another kind of branch which is essentially a completely separate tree of files in the same repository. For example, the Git repository itself contains heads named man and html that contain entirely different content from the master branch. I don't know what these types of branches are usually called.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 6
    I was looking for how to have two branches without common a ancestor commit and found this: http://madduck.net/blog/2007.07.11:creating-a-git-branch-without-ancestry/ – Nicolas Jun 27 '09 at 15:12
  • 1
    W.r.t. the seperate tree, I believe they are sometimes called an orphan branch, similar to how Github recommends you [create a github page manually](https://help.github.com/articles/creating-project-pages-manually) – max Dec 20 '13 at 16:32
  • 2
    Why do you say a topic branch have to be local? There's no reason to think you might not want to push a topic branch. And, similarly, other developers might make their own topic branches and you imght want to pull them. This answer seems to be confusing two totally unrelated properties of branches: whether a branch is local or not isn't related at all to whether it is a topic branch. – Jean-Paul Calderone Jan 03 '14 at 16:30
  • @Jean-PaulCalderone: I don't think I said topic branches *have* to be local. You can remote track a topic branch, of course, if there is more than one developer working on it. – Greg Hewgill Jan 03 '14 at 23:54
  • 2
    I think the answer implies it. Why is "... that you create locally ..." and "... have a name that is meaningful to you." an intrinsic part of what makes up a "topic branch"? The first sentence of your answer strongly suggests that these are important features of a topic branch but they're actually both orthogonal to a branch's "topicness" or not. The following paragraph where you describe "remote branches" re-inforces the idea that the "created locally" part of a topic branch is important. I suggest re-focusing this answer to de-emphasize these unrelated branch traits. – Jean-Paul Calderone Jan 05 '14 at 12:39
  • When I read this answer, I got the impression that you want to say that a topic branch is a Git concept, which it is not (correct me if I misunderstood your answer). From a Git point of view, a topic branch is just an ordinary branch, as @mipadi describes in his answer. – theDmi Jul 04 '15 at 09:01
  • why on earth?, another name. does the term "feature branch" not suffice? Aren't we overkilling over shelves? – OK999 Aug 10 '17 at 15:56
91

It's not a technical term; it just refers to a branch that was created to implement a specific feature or fix a bug. The "topic" is the reason for the creation of the branch, essentially.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • 3
    yep. as opposed to a personal branch, where you have branches: bob, alice, mat, etc. – webmat Nov 13 '08 at 14:28
  • 4
    ...so topic branch and feature branch are the same things, correct? – Betlista Jan 13 '20 at 21:04
  • 1
    @Betlista More or less, yes. – mipadi Jan 14 '20 at 22:02
  • 1
    I guess it's a more generic term for a feature branch. A "feature" branch could be a feature, or a bugfix, or an experiment, or something else perhaps. I guess it's an attempt to introduce a new name for arbitrary branches formerly known as "feature branches" which might not actually be a "feature" to avoid confusion. However, clearly it has created some confusion! – drkvogel Apr 06 '21 at 00:27
33

https://github.com/dchelimsky/rspec/wiki/Topic-Branches explains this well:

A “topic” branch is a separate branch that you use when working on a single “topic” (a bug fix, a new feature, or an experimental idea). Working on a topic branch instead of directly on top of “master” is recommended because:

{... visit link ...}

So, for all of these reasons it’s recommended to use a topic branch for preparing submissions even for simple contributions like single-commit bugfixes and the like.

This sample also gives examples. Which actually got me to thinking, this is probably what most shops do already. All of the agile projects I've ever been with do. I upvoted th "It's not a technical term" because I feel this hits the nail on the head.

Community
  • 1
  • 1
Jeff Ancel
  • 3,076
  • 3
  • 32
  • 39
4

it looks like the most prominent and important type of branches that aren't topic branches would be release branches on a major, publicly-available repository, right?

That's probably right for you, but that's about you and the project you're thinking about; it's not determined by Git.

Most version control systems (particularly centralized ones) prescribe or enforce a particular workflow, including what it makes sense to use a branch for. Git ( and to some extent most distributed VCSs) consider that workflow, what branches are used for, when to commit, what different repos are used for, etc. is all chosen by the users and agreements among the users (policies). So Git doesn't enforce these technically.

This is one of the things that made Git hard for me to learn. Oliver Steele explained this from user's view, writing about Commit Policies.

Hephaestus
  • 1,982
  • 3
  • 27
  • 35
Paul
  • 16,255
  • 3
  • 33
  • 25