Cherry-pick a commit automatically across multiple branches.
Use the MyPintMerge
command-line utility to automate cherry-picking a commit
from one branch to other branches. It's a .NET Core app, so it runs on Windows,
macOS, and Linux.
To run MyPintMerge
, specify the following arguments:
- A base name for the local branches
- The name of the remote branch that has the commit
- The commit SHA
- Your authentication credentials to the git repo
Run MyPintMerge
on the command-line in Windows, macOS, or Linux:
MyPintMerge <local-branch-base-name> <remote-branch-name> <commit-sha> <login> <password>
Specify the branches that receive the commit in appsettings.json, in the
repoManagement
section:
"repoManagement": {
"remoteRepoName": "upstream",
"repoLocalPath": "C:\\Users\\JimGalasyn\\Source\\Repos\\ksql",
"availableBranches": [
"master",
"0.9.0-ksqldb",
"0.9.x-ksqldb",
"0.8.1-ksqldb",
"0.7.1-ksqldb"
],
"sigName": "Jim Galasyn",
"sigEmail": "jim.galasyn@confluent.io"
},
Also in the repoManagement
section are settings for the remote repo name
and the path to your local clone of the repo.
MyPintMerge
implements the following workflow:
- Validate command-line arguments.
- Fetch the state of the remote repo.
- Get the source branch in the remote repo to cherry-pick from.
- Find the specified commit in the source branch.
- Get the names of the branches that will get the commit.
- Iterate through the branches. For each branch:
- Create and check out a local branch.
- Cherry-pick the commit to the local branch.
- Push the local branch to the tracked remote branch.
- Optionally delete the local branch. Set
deleteLocalBranches
in theappConfig
section of appsettings.json.
MyPintMerge
iterates through the list of available remote branches and
creates a corresponding local branch for each remote branch. This operation
is the equivalent of the following command-line:
git checkout -b <local-branch-name> -t <remote-repo-name>/<tracked-branch-name>
For example, the following command creates a local branch
named docs-2358
which tracks the remote branch named 0.8.1-ksqldb
in the remote repo named upstream
:
git checkout -b docs-2358 -t upstream/0.8.1-ksqldb
MyPintMerge
names a local branch by appending the remote branch name to the
provided base name. For example, if the base name is docs-2358
and the
tracked remote branch is named 0.8.1-ksqldb
, the local branch name is
docs-2358-0.8.1-ksqldb
.
If the cherry-pick causes a merge conflict, MyPintMerge
exits immediately
without changing any more state.
If no change to the branch is detected after the cherry-pick, which means that
the commit is already present in the branch, MyPintMerge
skips to the next
branch.
MyPintMerge
is implemented as a .NET Core console application. It uses the
libgit2sharp NuGet package to
interface with git.
For questions and feedback, please contact me at @JimGalasyn.