git helper scripts for managing feature branches and issuing pull requests. gitfeatures creates and pushes consistently named branches, opens pull requests against the right base branch, cleans up merged branches, and can write a changelog for each branch from a template you control.
- Python 3.10 or newer
- git, with a remote named
origin - GitHub or Bitbucket for pull requests
$ pip install git+https://github.com/robinedwards/gitfeatures.git
This installs the git feature, git hotfix, git release, git stable,
git releasecandidate, git pullrequest, git cleanup and git changelog commands.
To upgrade, run the same command with --upgrade. See Migrating from environment variables if
you configured an earlier version with environment variables.
gitfeatures works with no configuration for a GitHub repo whose base branch is main:
$ git feature new html_pruning # creates and pushes feature_html_pruning $ git pullrequest # opens a pull request for the current branch $ git feature finish # after the PR is merged: deletes the branch locally and on origin $ git cleanup # deletes local branches that are merged or gone from origin
To set a repo up for everyone who works on it, commit a .gitfeatures file:
$ git config --file .gitfeatures gitfeatures.masterBranch develop $ git config --file .gitfeatures gitfeatures.ticketPrefix ENG- $ git changelog --init-template # optional: per-branch changelogs from an editable template $ git add .gitfeatures changelog-template.md $ git commit -m "Configure gitfeatures"
Settings for a repository live in a .gitfeatures file at the top of its working tree, committed
so everyone who works on the repo gets the same behaviour:
[gitfeatures]
repo = github
masterBranch = develop
strategy = rebase
ticketPrefix = ENG-
ticketSeparator = -
requireTicketId = true
[changelog]
enabled = true
template = .github/changelog-template.md
The file uses git's own config format (the same as .git/config) and is read with
git config --file .gitfeatures, so you can edit it by hand or with git:
$ git config --file .gitfeatures gitfeatures.masterBranch develop $ git config --file .gitfeatures --unset gitfeatures.masterBranch $ git config --file .gitfeatures --list
- Section and key names are case-insensitive.
- A key written without a value (
requireTicketIdon its own line) meanstrue. - Boolean settings are true for
true,1,yesoron. Any other value is false. - Paths are absolute or relative to the top of the working tree.
- In a git worktree, the
.gitfeaturesof that worktree's checkout is used. - A file git cannot parse stops every command with git's error message.
Never put tokens or other secrets in .gitfeatures. It is meant to be committed, and gitfeatures only
reads secrets from the environment.
Every setting can also be set with an environment variable. The order of precedence is:
- the environment variable;
- the key in
.gitfeatures; - the default.
When an environment variable overrides a different value from .gitfeatures, gitfeatures prints a
notice to stderr, for example:
gitfeatures: GITFEATURES_MASTER_BRANCH='main' overrides gitfeatures.masterBranch = 'develop' from /path/to/repo/.gitfeatures
This makes a forgotten export in your shell profile visible. To override a setting for a single
command, set the variable for that command only:
$ GITFEATURES_STRATEGY=rebase git pullrequest
Each setting as a .gitfeatures key and as an environment variable:
gitfeatures.repo/GITFEATURES_REPO:github(default) orbitbucket.gitfeatures.masterBranch/GITFEATURES_MASTER_BRANCH: The repo's main branch, which new branches are normally created from.git pullrequestrefuses to run on it, and offers it as the base of a branch whose own base it can't work out (see Base branches). Default:main.gitfeatures.strategy/GITFEATURES_STRATEGY: Howgit pullrequestbrings a branch up to date with the base branch:merge(default) orrebase.gitfeatures.forkPrStrategy/GITFEATURES_FORK_PR_STRATEGY: If set toprivateon GitHub, uses the compare view instead of the new-PR shortcut.gitfeatures.branchSeparator/GITFEATURES_BRANCH_SEPERATOR: Separator between the parts of a branch name. Default:_.gitfeatures.ticketSeparator/GITFEATURES_TICKET_SEPERATOR: Separator between the ticket id and the name. Default: the branch separator.gitfeatures.ticketPrefix/GITFEATURES_TICKET_PREFIX: Prefix added to ticket ids that do not already have it (e.g.ENG-).gitfeatures.requireTicketId/GITFEATURES_REQUIRE_TICKETID: When true,git feature newrequires a ticket id. Default:false.gitfeatures.debug/GITFEATURES_DEBUG: When true, prints debug output. Default:false.changelog.enabled/GITFEATURES_CHANGELOG_ENABLED: When true,git feature newwrites a changelog for the new branch, andgit pullrequestuses it as the PR description. Default:false. See Changelogs.changelog.template/GITFEATURES_CHANGELOG_TEMPLATE: Changelog template file. See Changelog template.
The environment variables keep their original spelling (SEPERATOR) for compatibility.
These are environment variables only, because they are secrets or per-command switches that do not belong in a committed file:
GITHUB_TOKEN(orGH_TOKEN): Letsgit pullrequestcreate GitHub PRs through the API. See git pullrequest.LINEAR_API_KEY(orLINEAR_TOKEN): See Linear integration.CONSOLEONLY: If set,git pullrequestprints the PR URL instead of creating or opening the PR.
Earlier versions were configured only with environment variables, usually exported from a shell
profile. Those still work unchanged. To move a repo's settings into .gitfeatures:
Write each exported value into the repo's
.gitfeatures, using the key from Settings. For example,export GITFEATURES_TICKET_PREFIX=ENG-becomes:$ git config --file .gitfeatures gitfeatures.ticketPrefix ENG-
Commit
.gitfeatures.Remove the
exportlines from your shell profile. While they remain, they win over.gitfeaturesin every repo, and gitfeatures prints a notice wherever they disagree.
If your repo has a changelog-template.md at its root, it keeps working. To make it explicit, add
changelog.template = changelog-template.md under [changelog].
These scripts follow the GitHub flow:
each change is made on a short-lived branch created from the base branch, reviewed in a pull request,
merged, and then deleted. git release, git stable and git hotfix add date-stamped branches
for teams that cut releases.
git feature new <name> [<ticket_id>] [--base <branch>]: Create and push afeature_<name>branch from the current branch. If<ticket_id>is given, the branch isfeature_<ticket_id>_<name>, using the configured separators and ticket prefix. You are asked to confirm if you are not ongitfeatures.masterBranch(or detached at its tip) and didn't pass--base. The new branch's base is recorded (see Base branches):--base <branch>if given, otherwise the current branch. Ifchangelog.enabledis on, a changelog file is written for the branch (see Changelogs).git feature finish [<name>] [--base <branch>]: Delete the current feature branch (or the named one) locally and on origin. It works out the branch's base the same way asgit pullrequest(see Base branches) and refuses if the branch has commits that are not inorigin/<base branch>, so merge the PR first. When finishing the current branch it then switches to the base branch, or, if another worktree has the base branch checked out, detaches HEAD atorigin/<base branch>. A named branch that is checked out in another worktree has to be finished from that worktree. If origin has already deleted the branch, for example GitHub after the merge, only the local branch is deleted.
You can also pass a full branch path in the feature/ENG-123-description style that tools such as
Linear suggest. With this in .gitfeatures:
[gitfeatures]
ticketSeparator = -
ticketPrefix = ENG-
running git feature new feature/ENG-123-description creates feature/ENG-123-description,
normalising the ticket id to ENG-123 and keeping the hyphens and the slash.
git releasecandidate new [<name>]: Same asgit feature newwith thereleasecandidateprefix. Without a name, today's date (YYYY-MM-DD) is used.git releasecandidate finish [<name>]: Same asgit feature finish.
These create and switch between date-stamped branches:
git release new [<suffix>]: Create and pushrelease_YYYYMMDD_<suffix>from the current checkout, recording the current branch as its base. Without a suffix, the current time (HHMMSS) is used. If more than three release branches exist, you are asked whether to delete the oldest.git release: Check out the latestrelease_YYYYMMDD…branch on origin.
git stable and git hotfix work the same way with the stable and hotfix prefixes.
Opens a pull request from the current branch into its base branch:
- Refuses to run on
gitfeatures.masterBranch. - Works out the branch's base branch (see Base branches) and prints it.
- If the branch is behind
origin/<base branch>, offers to update it: it fetches the base branch from origin and runsgit merge origin/<base branch>, orgit rebase origin/<base branch>(seegitfeatures.strategy), on the current branch. It never checks out the base branch, so it works in a git worktree while the base branch is checked out in another worktree. If there are conflicts it stops: fix them,git addthe fixed files, rungit commit(orgit rebase --continue), then rungit pullrequestagain. - Offers to push unpushed commits.
- Creates or opens the PR against the base branch:
- With
GITHUB_TOKENorGH_TOKENset, on GitHub, it creates the PR through the API as a draft, titled with the branch name. Ifchangelog.enabledis on and the branch's changelog file exists, the file becomes the PR description. It then opens the PR in your browser. If the API call fails, it falls back to the browser flow below. - Otherwise it opens the "new pull request" page for GitHub or Bitbucket in your browser.
- With
git pullrequest --dry-run, or CONSOLEONLY=1, prints the PR URL instead of creating or opening
anything. git pullrequest --base <branch> sets the branch's base branch.
Each branch has a base branch: the branch it was created from. git pullrequest brings the branch up
to date with it and opens the pull request against it, and git feature finish checks the branch has
been merged into it. Neither needs to check out a base branch that another worktree is using, so both
work in a git worktree while the base branch is checked out in another worktree. So a branch created from release_20261101 is merged with and opened against
release_20261101, not main.
gitfeatures keeps each branch's base in the repo's git config as branch.<name>.gitfeaturesBase,
which git renames and deletes along with the branch. git pullrequest takes the base from, in order:
--base <branch>(git feature finishtakes it too);branch.<name>.gitfeaturesBase, recorded whengit feature new(orgit release newand the like) created the branch, or by an earliergit pullrequest;- the branch git's reflog says the branch was created from, for branches made with git directly, such
as
git worktree add -b <name> <path> origin/mainorgit switch -c <name> release_20261101. Git records onlyHEADforgit checkout -b <name>with no start point, so this can't help there; - otherwise it asks whether the base is
gitfeatures.masterBranch. Answernand rerun with--base <branch>.
When git feature new (or git release new and the like) starts from a detached HEAD, as in
git worktree add --detach <path> origin/main, there is no current branch to record, so it:
- records
gitfeatures.masterBranchwithout asking when HEAD is at the tip oforigin/<masterBranch>or the localmasterBranch; - otherwise asks
Which branch is <name> based on? [<masterBranch>](an empty answer meansmasterBranch) and checks the answer exists on origin; - with no answer on stdin, for example in a script that pipes in only
y, exits before creating the branch and asks you to rerun with--base <branch>. It never guesses.
git feature new <name> --base <branch> records <branch> (which has to be on origin) without
asking anything, so scripts can use it.
Whatever it uses is recorded, so later runs agree. To change a branch's base, rerun with --base or
run git config branch.<name>.gitfeaturesBase <branch>.
Deletes local branches you no longer need, after fetching from origin with --prune:
- branches merged into
origin/<their base branch>(see Base branches) or intoorigin/<gitfeatures.masterBranch>; - branches whose upstream branch has been deleted on origin, such as the ones GitHub deletes after a squash merge. Their commits are not in the base branch, so check the list before you confirm.
It never deletes gitfeatures.masterBranch or a branch that is checked out in any worktree, and it
only deletes local branches: nothing on origin changes. It lists the branches and why each one goes,
then asks before deleting them.
git cleanup --dry-run: List the branches without deleting anything.git cleanup --yes: Delete them without asking.
Renders the changelog template for a branch without creating the branch, or sets up a template:
$ git changelog # print the changelog for the current branch $ git changelog --branch feature/ENG-123-change # ... for another branch name $ git changelog --ticket ENG-123 # ... with this ticket id (fetched from Linear if configured) $ git changelog --write # write it to changelog/<branch>.md $ git changelog --write --out /tmp/preview.md # ... or to another file $ git changelog --init-template # copy the default template into the repo $ git changelog --init-template --out .github/changelog-template.md --force
--init-template cannot be combined with --branch, --ticket or --write. See
Changelog template.
When changelog.enabled is on, git feature new writes changelog/<branch>.md for the new
branch, leaving out the feature/ prefix: feature/ENG-123-change gets
changelog/ENG-123-change.md. An existing file is not overwritten. The file is not committed for
you. Fill it in as you work and commit it with your changes. git pullrequest uses it as the PR
description when it creates the PR through the API.
Changelogs are rendered with Jinja2 from a template. gitfeatures ships a default template (gitfeatures/templates/changelog-template.md) with Purpose, Background, Changes, Testing and Links sections. To use your own, copy the default into your repository and edit it:
$ git changelog --init-template Wrote /path/to/repo/changelog-template.md Set changelog.template = changelog-template.md in /path/to/repo/.gitfeatures Set changelog.enabled = true in /path/to/repo/.gitfeatures Edit the template, then commit it and .gitfeatures.
--init-template writes the default template to changelog-template.md (or to --out <path>,
relative to the top of the working tree, or wherever changelog.template already points) and records
the path as changelog.template in .gitfeatures. If .gitfeatures does not already set
changelog.enabled, it sets it to true. It will not overwrite an existing file unless you pass
--force.
The template is chosen in this order:
changelog.template(orGITFEATURES_CHANGELOG_TEMPLATE). If that file does not exist, gitfeatures prints a warning and uses the bundled default.changelog-template.mdat the top of the working tree, for repos set up beforechangelog.templateexisted.- The bundled default.
Run git changelog after editing the template to see what a new branch will get. For example, to add
a rollout checklist to every changelog:
## Rollout
- [ ] Feature flag created
- [ ] Docs updated
{% if ticket %}- [ ] {{ ticket }} moved to Done{% endif %}
Variables available to the template:
branch: the branch name.ticket: the ticket id (e.g.ENG-123), if one was given or found in the branch name.title: the issue title if there is one, else the branch name.background: the issue description, if there is one.changes,testing:"- ", a starting bullet.repo_full_name:owner/namefrom theoriginURL, andrepo_origin: the URL itself. Both are empty if there is noorigin.master_branch: the base branch.now: the current UTC time, e.g.2026-01-31T09:30:00.000000Z.issue: the ticket in a provider-neutral form:provider,id,key,title,description,urland the other fields below. Empty if there is no issue.linear: the Linear issue, if one was fetched:identifier,number,title,description,url,createdAt,updatedAt,priority,estimate,team(key,name),state(name,type),assignee(name,displayName,email) andlabels(each withname). Empty otherwise.
As in any Jinja2 template, a single trailing newline is dropped, and a variable that is not set renders
as an empty string. If the template cannot be read or rendered, the changelog is created empty. Set
gitfeatures.debug to see why.
If you track work in Linear, gitfeatures can fill the changelog from the
ticket. Set LINEAR_API_KEY in your environment (never in .gitfeatures), and give a ticket id in
either form:
$ git feature new my_change 123 # with ticketPrefix = ENG-, uses ENG-123 $ git feature new feature/ENG-123-some-description # see "git feature" above
If the issue is found, the template gets title, background, issue and linear from it
(the default template shows the ticket's details and links to it). If no key is set or the issue is not
found, the changelog is still created from the template without them. Only the team key and number
(ENG and 123) are used to look the issue up.
gitfeatures: GITFEATURES_… overrides … from …/.gitfeatures- An environment variable, usually exported from your shell profile, is overriding the repo's
.gitfeatures. Remove the export if the file should win. See Migrating from environment variables. gitfeatures.core: unable to read …/.gitfeatures: fatal: bad config line ….gitfeaturesis not valid git config. Check it withgit config --file .gitfeatures --list.gitfeatures: changelog template … (set by …) does not exist, so the bundled default is usedchangelog.templateorGITFEATURES_CHANGELOG_TEMPLATEpoints at a missing file. The message names the setting that pointed there. Paths are relative to the top of the working tree.gitfeatures doesn't know which branch <branch> was created from. Was it <main branch>?- Neither a recorded base nor git's reflog says where the branch came from. Answer
yif it wasgitfeatures.masterBranch; otherwise answernand rerun with--base <branch>. See Base branches. HEAD is detached. Which branch is <name> based on?git feature newstarted from a detached HEAD that is not at the tip ofgitfeatures.masterBranch. Type the base branch, or press Enter formasterBranch. If it ran out of input it exits withno answer on stdin: rerun with--base <branch>.the base branch <branch> (…) is not on origin- The base branch is local only, or has been deleted on origin, for example after it was merged.
Push it, or pass
--baseto choose another base. can't issue pull requests on <branch>- You are on the base branch. If that is not your base branch, set
gitfeatures.masterBranch. none zero exit status executing: git …- A git command failed, often because there is no
originremote or the branch does not exist on it. Run the git command shown to see git's own error.
To see what gitfeatures is doing, including which changelog template it uses, set
gitfeatures.debug = true or run with GITFEATURES_DEBUG=1.
See CONTRIBUTING.md for setting up a development environment, running the tests and adding a setting.
MIT