Backport commits to multiple branches
Cherry-picks a commit to one or more branches, handling conflicts and restoring your original branch. Use it to backport fixes to multiple release branches, with an option to create new branches for pull requests.
/plugin marketplace add openshift-eng/ai-helpers/plugin install git@ai-helpers<commit> <branch1> [branch2...] [--new-branch]git:backport
/git:backport <commit> <branch1> [branch2...] [--new-branch|-b]
The git:backport command helps backport a commit to multiple branches. It automates the process of cherry-picking a commit to one or more target branches, with optional support for creating new branches for each backport (useful for creating pull requests).
This command provides:
The command executes the following workflow:
Validates inputs:
--new-branch or -b flag if presentgit cat-file -t <commit>git log -1 --oneline <commit>ASK FOR USER PERMISSION:
Saves current state (only after user permission):
git branch --show-currentgit status --porcelainFor each target branch (only after user permission):
git checkout <branch>git rev-parse --abbrev-ref <branch>@{upstream}git pull--new-branch flag is set:
git checkout -b backport-<commit-short-hash>-to-<branch>
backport-abc1234-to-release-1.0git cherry-pick <commit>git statusgit diffgit cherry-pick --continue when done, or git cherry-pick --abort to skipRestores original state:
git checkout <original-branch>--new-branch was used)--new-branch was used, reminds user they can now create PRs from the new branchesThe command is interactive and waits for user input when conflicts occur and REQUIRES USER PERMISSION before executing any git operations. It tracks success/failure for each branch and provides a comprehensive summary at the end.
--new-branch flag was used)Basic backport to a single branch:
/git:backport abc1234 release-1.0
Cherry-picks commit abc1234 directly to the release-1.0 branch.
Backport to multiple branches:
/git:backport abc1234 release-1.0 release-1.1 release-1.2
Cherry-picks commit abc1234 to three different release branches.
Backport with new branch creation (for PRs):
/git:backport abc1234 release-1.0 release-1.1 --new-branch
Creates new branches backport-abc1234-to-release-1.0 and backport-abc1234-to-release-1.1, each containing the cherry-picked commit. These branches can then be used to create pull requests.
Using short flag syntax:
/git:backport abc1234 main -b
Same as --new-branch, creates a new branch backport-abc1234-to-main.
--new-branch or -b: Create a new branch from each target branch before cherry-picking (optional flag)