Skip to main content

Cherry-pick commits across GitHub repositories using only the GitHub API

Project description

GitHub cherry-pick

Cherry-pick commits across GitHub repositories using only the GitHub API.

Uses the algorithm described by Jim's Stack Overflow answer to perform a cherry-pick entirely through the GitHub REST API. This is much better than doing that through patches (e.g. patch2pr), because git is much smarter with resolving conflicts on commits instead of patches.

When I used patch2pr, I had to constantly rebase my patches, because on almost every update they would raise conflicts. Cherry-picking those commits works perfectly fine!

Installation

Requires Python 3.10+, I recommend using uv, but it will work fine with pip or anything else.

uv tool install gh-cherry-pick

Or run directly without installing:

uvx gh-cherry-pick --help

Usage

This tool requires a classic token with repo and workflow permissions (workflow is needed only if commits update .github/workflows files) or a fine-grained token with contents and workflows permissions.

GITHUB_TOKEN=ghp_... gh-cherry-pick \
  --target MyOrg/nixpkgs@patched \
  `: # cherry-pick these commits` \
  NixOS/nixpkgs/3f5ba52cc4701bf341457dfe5f6cb58e0cbb7f83 \
  NixOS/nixpkgs/49ba75edefc8dc4fee45482f77a280ddd7121797 \
  `: # or merge the entire branch!` \
  Someone/nixpkgs@pr-branch

You can also pass links like https://github.com/NixOS/nixpkgs/commit/4e92bbcdb030f3b4782be4751dc08e6b6cb6ccf2 or https://github.com/MyOrg/nixpkgs/tree/patched instead of MyOrg/nixpkgs@patched.

Arguments

You can give commits and/or branches as positional arguments. Commits will be cherry-picked, while branches will be merged into the target. Each commit/branch is applied in order and builds on the previous result.

Format for branches is Owner/Repo@branch and for commits is Owner/Repo/commit.

  • --target: Required. Target branch to which to apply cherry-picks.
  • --first-hard-reset-to: Hard reset target to this commit, before doing anything else.
  • --token/-t: GitHub token. If not specified, falls back to the $GITHUB_TOKEN environment variable.

Development

uv sync
uv run pre-commit install

Then commit your changes and send a pull request!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh_cherry_pick-1.3.1.tar.gz (57.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gh_cherry_pick-1.3.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file gh_cherry_pick-1.3.1.tar.gz.

File metadata

  • Download URL: gh_cherry_pick-1.3.1.tar.gz
  • Upload date:
  • Size: 57.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gh_cherry_pick-1.3.1.tar.gz
Algorithm Hash digest
SHA256 89c5948d300e2c953643ddbec0fb67eeb49512dec4ce92deeed7d0d4aabd2582
MD5 1d2c0fc1632c80a077e6c221c641bccd
BLAKE2b-256 dd0ca552e9f0e4d3b92f23a1318990e29ad82f4ba9181691d504f63be7964551

See more details on using hashes here.

Provenance

The following attestation bundles were made for gh_cherry_pick-1.3.1.tar.gz:

Publisher: publish.yml on PerchunPak/gh-cherry-pick

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gh_cherry_pick-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: gh_cherry_pick-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gh_cherry_pick-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 756f15399bf555657852c3c2c32fd4e38e94e7dcf1bbffa6b7312d1977ea4851
MD5 af17d0b34d2c790d4dc84d49dee7a4b0
BLAKE2b-256 036d53334ad3e506b51176f151413ef7f6f8a1e517fa999693a02fa4ea2765a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for gh_cherry_pick-1.3.1-py3-none-any.whl:

Publisher: publish.yml on PerchunPak/gh-cherry-pick

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page