Skip to main content
v2026.11,986 entries · CC-BY 4.0

Feature Branch in Git: Create, Merge and Delete One

A git feature branch is a short-lived branch for one piece of work. See the create, merge and delete commands and the output Git prints at each step.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

A feature branch in Git is a branch you create to build one feature or piece of related work, keep apart from your stable code, and delete once it has been merged. Git has no separate “feature branch” object: it is an ordinary branch used in a particular way. The Pro Git book calls the same thing a topic branch, and GitHub Docs say “a feature branch or topic branch”. This guide walks through the full lifecycle (create, commit, merge, delete) with the commands and the messages Git prints, as documented by Git and GitHub.

What it is used for in research

Research projects keep analysis scripts, simulation code, data-cleaning pipelines and manuscript sources in Git. A feature branch lets you change one of these without touching the version everyone else relies on. Pro Git defines a topic branch as “a short-lived branch that you create and use for a single particular feature or related work”, and notes that topic branches “are useful in projects of any size”, including a single-person project.

The idea contrasts with long-running branches. In the workflow Pro Git describes, a long-running branch such as master holds only entirely stable code, and work is pulled in from topic branches when it is ready. Because branching in Git is lightweight, Pro Git says it is “common to create, work on, merge, and delete branches several times a day”.

Typical research uses include trying a new statistical model on a copy of the analysis, fixing one figure script, or adding one preprocessing step, all while the main line of the project stays runnable. If you want to compare what a branch changed, see how to compare two branches in Git.

Install or access

Git is used from the command line, and its commands are documented in the official reference at git-scm.com/docs and in the free Pro Git book at git-scm.com/book. The commands below come from those two sources.

On GitHub, you must have write access to a repository to create a branch in it, and you always create a branch from an existing branch (GitHub Docs, About branches). If you do not have write access, work in a copy of the repository instead; see how to fork a repository. New to the platform? Start with GitHub tutorials for beginners.

Step-by-step: create, commit, merge and delete a feature branch

  1. Create the branch and switch to it. Run git switch -c iss53. The git-switch reference gives the form git switch (-c|-C) <new-branch> [<start-point>]: -c creates the branch at the start point before switching, and is equivalent to git branch iss53 followed by git switch iss53. The Pro Git book uses the older command, git checkout -b iss53, which prints Switched to a new branch "iss53" and is shorthand for the same two steps. Replace iss53 with your own branch name.
  2. Check which branch you are on. git branch --show-current prints the name of the current branch (in detached HEAD state nothing is printed).
  3. Do the work and commit it on the feature branch as usual. Work parked half-done can be set aside with git stash, and changes you decide not to keep can be dropped as described in how to discard local changes in Git.
  4. Check out the branch you want to merge into. Pro Git is explicit that you check out the branch you merge into, then merge the other one in: switch to the target branch, then run git merge iss53.
  5. Delete the merged branch. git branch -d iss53 deletes it and prints a line such as Deleted branch hotfix (3a0874c). (the book’s example uses a branch called hotfix).

On GitHub, a feature branch is normally merged through a pull request. GitHub Docs describe protected branches, which let maintainers block force pushes and deletion, and require status checks, reviews, code owner approval or signed commits before merging. Status checks are often the output of continuous integration.

Output and how to read it

A clean merge

When the target branch has no divergent work since you branched, Git does not create anything new: as Pro Git puts it, Git “simply moves the pointer forward”. This is called a fast-forward merge. If both branches have moved, Git combines the two histories instead.

A merge conflict

If both branches changed the same part of the same file, the merge stops. The book’s example output is:

CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Git “has paused the process while you resolve the conflict”. Edit the named file, then run git add on each file to mark it resolved, and finish the merge with a commit.

Deleting

The delete message Deleted branch hotfix (3a0874c). shows the branch name and the abbreviated commit the branch pointed at.

Troubleshooting

Git refuses to delete the branch

According to the git-branch reference, -d (--delete) requires that “the branch must be fully merged in its upstream branch, or in HEAD if no upstream was set”. -D is a “shortcut for –delete –force”. Use -D only when you intend to throw away work that has not been merged.

A merge stopped with a CONFLICT message

Nothing is lost: Git has paused. Resolve each conflicted file, run git add on it, then commit, as described above.

Deleting a branch on GitHub while its pull request is open

GitHub Docs say that deleting a branch with an open pull request closes the pull request, so merge or close the pull request before deleting the branch. After a pull request is merged and its head branch is deleted, GitHub automatically updates any other pull requests that were based on it, changing their base branch to the merged pull request’s base branch.

You cannot create the branch on GitHub

You must have write access to the repository. Without it, create a fork instead (see fork Git).

Free alternatives

The table lists the documented ways to do each step and what the official sources say about them.

Task Method What the source says
Create and switch git switch -c <new-branch> Creates the branch at the start point, then switches; equivalent to git branch then git switch (git-switch reference).
Create and switch git checkout -b <new-branch> Shorthand for git branch plus git checkout; prints Switched to a new branch (Pro Git).
Delete after merge git branch -d <branch> Branch must be fully merged in its upstream, or in HEAD if no upstream is set (git-branch reference).
Delete unmerged work git branch -D <branch> Shortcut for --delete --force (git-branch reference).
Delete on GitHub Branch dropdown, “View all branches”, trash icon, confirm Deleting a branch with an open pull request closes the pull request (GitHub Docs).

FAQ

What is a feature branch in Git?

It is a branch created to build one feature or related piece of work, kept separate from stable code until it is merged. GitHub Docs: “A branch you create to build a feature is commonly called a feature branch or topic branch.”

Is a git feature branch the same as a topic branch?

Yes. Pro Git uses the term topic branch for “a short-lived branch that you create and use for a single particular feature or related work”, and GitHub Docs treat “feature branch” and “topic branch” as names for the same thing. Git itself treats both as an ordinary branch.

How long should a feature branch live?

Pro Git describes topic branches as short-lived, created, worked on, merged and deleted, often several times a day. By contrast, long-running branches hold stable code that topic branches are merged into.

Which branch do I check out before merging a feature branch in Git?

The branch you want to merge into. Check it out, then run git merge with the feature branch name.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Feature Branch in Git: Create, Merge and Delete One

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →