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
- Create the branch and switch to it. Run
git switch -c iss53. The git-switch reference gives the formgit switch (-c|-C) <new-branch> [<start-point>]:-ccreates the branch at the start point before switching, and is equivalent togit branch iss53followed bygit switch iss53. The Pro Git book uses the older command,git checkout -b iss53, which printsSwitched to a new branch "iss53"and is shorthand for the same two steps. Replaceiss53with your own branch name. - Check which branch you are on.
git branch --show-currentprints the name of the current branch (in detached HEAD state nothing is printed). - 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.
- 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. - Delete the merged branch.
git branch -d iss53deletes it and prints a line such asDeleted branch hotfix (3a0874c).(the book’s example uses a branch calledhotfix).
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
- Pro Git, “Branching Workflows”: git-scm.com/book/en/v2/Git-Branching-Branching-Workflows (checked 29 October 2026)
- Pro Git, “Basic Branching and Merging”: git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging (checked 29 October 2026)
- Git reference, git-switch: git-scm.com/docs/git-switch (checked 29 October 2026)
- Git reference, git-branch: git-scm.com/docs/git-branch (checked 29 October 2026)
- GitHub Docs, “About branches”: docs.github.com, About branches (checked 29 October 2026)
- GitHub Docs, “Creating and deleting branches within your repository”: docs.github.com, Creating and deleting branches (checked 29 October 2026)







