git cherry-pick <commit-range>
This command lets you selectively bring specific commits from somewhere else in the repository history into your current branch, effectively copying their changes without merging whole branches together.
It works by taking the commits specified by <commit-range> (for example abc123..def456 or abc123^..def456) and replaying their changes on top of your current HEAD, creating new commits with the same diffs but new hashes; you can also use forms like A..B (everything after A up to and including B), A^..B (including A itself) or even a single commit hash instead of a range, and add flags such as -n/--no-commit (apply the changes but leave them staged so you can adjust before committing), -e/--edit (open the commit message in your editor), -x (append a line to the commit message noting the original commit hash) and -s/--signoff (add a Signed-off-by line to the commit message) to control how the picked commits are created.
This is especially useful when you want to backport a bugfix from main into a release branch, or share a feature commit between two long-lived branches without pulling in all other unrelated history, and you can resolve conflicts similarly to merges whenever the changes do not apply cleanly; you can also continue, skip, or abort a conflicted sequence using git cherry-pick --continue, git cherry-pick --skip, and git cherry-pick --abort respectively.
Common variations and related commands include git cherry-pick <single-commit> when you only need one change, git cherry-pick <commit1> <commit2> <commit3> to pick non-contiguous commits, git cherry-pick -n <commit-range> when you plan to squash multiple picked commits into a single commit, and using git log --oneline or git log --oneline <branch> beforehand to discover which commit hashes or ranges you want to pick; for broader history movement you might instead use git merge <branch> (to bring in all changes from another branch) or git rebase <branch> (to replay a whole branch onto a new base, which internally uses mechanisms similar to cherry-picking).
Examples:
git cherry-pick abc1234..def5678git cherry-pick feature-start^..feature-endgit cherry-pick -x bugfix1..bugfix3