Automated Git Backport CLI Tool
Backport is an interactive CLI tool designed to streamline the process of backporting Git commits across multiple release branches. It automates the selection of commits and target branches, handles cherry-picking, pushes changes, and creates pull requests (PRs) on platforms like GitHub. The tool operates in a temporary directory, ensuring it never interferes with a user's local working copy or unstaged changes. Currently at stable version 11.0.2, it sees regular patch and minor releases, maintaining an active development pace. Its key differentiators include an intuitive interactive interface, non-intrusive operation, and a comprehensive workflow from commit selection to PR creation. A GitHub Action wrapping the CLI is also available for CI/CD integration.
Common errors
-
Error: Missing access token. Please add a personal access token to ~/.backport/config.json
cause GitHub Personal Access Token is not configured or is invalid.fixAdd a valid `accessToken` to `~/.backport/config.json` with necessary scopes (repo, workflow). -
Error: The 'backport' command could not be found. Make sure it's installed globally or run with npx.
cause The `backport` package is not installed globally or `npx` is not being used to execute it.fixRun `npm install -g backport` to install globally, or execute with `npx backport` if installed locally. -
Error: Node.js v18.x is not supported. Please upgrade to Node.js >=22.0.0.
cause An incompatible Node.js version is being used.fixUpgrade your Node.js environment to version 22.0.0 or newer. Use a Node Version Manager like `nvm install 22 && nvm use 22`.
Warnings
- breaking Version 10.0.0 introduced a breaking change by upgrading the minimum required Node.js version to 20.
- breaking Versions 10.0.2 and later (including all 11.x releases) bumped the minimum required Node.js version to 22.0.0. Older Node versions will cause execution errors.
- gotcha The `backport` CLI tool requires a GitHub Personal Access Token (`accessToken`) configured in `~/.backport/config.json`. Without it, operations that interact with GitHub APIs (like creating PRs) will fail.
- gotcha The `backport` tool performs all Git operations in a temporary directory (`~/.backport/repositories/`) to avoid interfering with your local working copy. Changes made by `backport` will not be visible in your local repository until the created PRs are merged and you pull them.
Install
-
npm install backport -
yarn add backport -
pnpm add backport
Imports
- backportRun
const { backportRun } = require('backport')import { backportRun } from 'backport' - BackportOptions
import { BackportOptions } from 'backport'import type { BackportOptions } from 'backport' - run
import { run } from 'backport'import { run } from 'backport/cli'
Quickstart
{
// .backportrc.json in repository root
"repoOwner": "your-org",
"repoName": "your-repo",
"targetBranchChoices": ["main", "release/1.0", "release/2.0"],
"autoMerge": true,
"autoMergeMethod": "squash",
"branchLabelMapping": {
"^auto-backport-to-(.+)$": "$1"
}
}
// ~/.backport/config.json (global config)
{
"accessToken": "ghp_YOUR_VERY_SECRET_GITHUB_TOKEN"
}
// Terminal
npm install -g backport
npx backport