Skip to content

Instantly share code, notes, and snippets.

@grafikchaos
Last active October 9, 2023 17:30
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save grafikchaos/8223422 to your computer and use it in GitHub Desktop.
Save grafikchaos/8223422 to your computer and use it in GitHub Desktop.
Cherry pick multiple commits from a remote or upstream branch

Cherry pick multiple commits from a remote or upstream branch into your local branch.

Saw this from a comment on an answer on Stack Overflow

git fetch upstream
git cherry-pick A^..B

where A is the commit hash you want to start from (the ^ will include commit A instead of starting at next commit after A) and B is the commit you want to end after being applied.

If you run into merge conflicts, it's a simple process of:

  1. manually fixing the merge conflicts
  2. committing your changes (you may need to do this several times if you use the -p option)
  • git add -p - this will walk you through your changes and allow you to stage chunks instead of whole files so your commit messages can be more verbose/useful.
  • git commit
  1. continue the cherry picking (git cherry-pick --continue)
@untra
Copy link

untra commented Dec 18, 2018

💯

@ihomway
Copy link

ihomway commented Sep 30, 2019

🍺

@osamaramihafez
Copy link

osamaramihafez commented Mar 1, 2022

Tried doing this, but encounter an error fatal: bad revision firsthash^-lasthash

Edit: Nvm turns out I was using a - instead of ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment