git cherry-pick should be your answer here.

Apply the change introduced by an existing commit.

Do not forget to read bdonlan's answer about the consequence of cherry-picking in this post:
"Pull all commits from a branch, push specified commits to another", where:

A-----B------C
 \
  \
   D

becomes:

A-----B------C
 \
  \
   D-----C'

The problem with this commit is that git considers commits to include all history before them

Where C' has a different SHA-1 ID.
Likewise, cherry picking a commit from one branch to another basically involves generating a patch, then applying it, thus losing history that way as well.

This changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this).
More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.

Answer from VonC on Stack Overflow
๐ŸŒ
DEV Community
dev.to โ€บ iamafro โ€บ how-to-merge-a-specific-commit-into-another-branch--oak
How to merge a specific commit into another branch - DEV Community
February 15, 2018 - First you checkout the branch you want to merge the commits into ... What this does is, "It applies the change introduced by the commit at the tip of the working branch and creates a new commit with this change". The issue I had with that was, I had made a couple of commits and I needed all those commits in the master branch. That's when I found it. What did I find? you may be asking. Gitlens ...
๐ŸŒ
Git
git-scm.com โ€บ docs โ€บ git-merge
Git - git-merge Documentation
Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch. This command is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another.
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ git-cherry-pick-selecting-specific-commits-to-merge-f1bf245e052a
Git Cherry Pick - Select specific commits to merge | by Carlos Fernando Arboleda Garcรฉs | Better Programming
December 13, 2023 - git checkout main_cherry_pick git cherry-pick 12670fd 14b185a df931e3 1441727 2296bb0 ยท If you donโ€™t have any conflict, you will see one commit confirmation for each selected/included commit in your cherry-pick command: ... Finally, you need to push the changes in your main_cherry_pick to the remote branch. Then you have to do a normal merge from main_cherry_pick into the main branch.
๐ŸŒ
Reddit
reddit.com โ€บ r/git โ€บ how to merge branches to a specific commit
r/git on Reddit: How to merge branches to a specific commit
January 14, 2021 -

I have two branches, main and develop. Lets say that this is my current commit history:

A - B - C - D (main) (tag 1.0.0) - E - F - G (tag 1.0.1) - H (develop)

I want to bring main to G (tag 1.0.1) so that it is one commit behind develop. Note that, I want all commits between main and G to also be included. Would I use cherry-pick or is there a better way?

๐ŸŒ
Git
git-scm.com โ€บ book โ€บ en โ€บ v2 โ€บ Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
All you have to do is check out the branch you wish to merge into and then run the git merge command: $ git checkout master Switched to branch 'master' $ git merge iss53 Merge made by the 'recursive' strategy. index.html | 1 + 1 file changed, 1 insertion(+) This looks a bit different than the ...
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ git โ€บ git_branch_merge.asp
Git Branch Merge
If you want to always create a ... from a branch into a single commit (instead of keeping every commit), use git merge --squash branchname....
๐ŸŒ
Atlassian
atlassian.com โ€บ git โ€บ tutorials โ€บ using branches โ€บ git merge
Git Merge | Atlassian Git Tutorial
Once the previously discussed "preparing to merge" steps have been taken a merge can be initiated by executing git merge <branch name> where <branch name> is the name of the branch that will be merged into the receiving branch.
๐ŸŒ
GitLab
docs.gitlab.com โ€บ topics โ€บ git โ€บ cherry_pick
Cherry-pick changes with Git | GitLab Docs
To specify the second parent, which is often the last commit before the feature branch merged, use -m 2. These flags determine which changes Git applies to your current branch. To cherry-pick the merge commit from branch feature-1 into your current working branch:
๐ŸŒ
Quora
quora.com โ€บ How-do-you-merge-code-of-two-people-working-on-the-same-branch-with-different-commits-Python-Django-Git-GitLab-development
How to merge code of two people working on the same branch with different commits (Python, Django, Git, GitLab, development) - Quora
Use when you want to preserve both commit histories and avoid rewriting published history. ... Ensure integrate branch is up to date: git checkout integrate/feature && git pull origin feature-branch ยท Merge the other developerโ€™s branch (if their work is on a different branch) or ensure both sets of changes are present locally. git merge --no-ff origin/feature-branch (if merging remote branch into ...
๐ŸŒ
Namehero
namehero.com โ€บ blog โ€บ using-git-cherry-pick-to-apply-a-commit-from-another-branch
Using Git Cherry-Pick To Apply A Commit From Another Branch
October 30, 2024 - The cherry-pick command allows you to pick a specific commit from another git branch and bring it into your current branch. ... The cherry-pick sub-command in git is used to apply a single commit from one branch and apply it to the current branch ...
๐ŸŒ
SoftwareTestingo
softwaretestingo.com โ€บ home โ€บ tools โ€บ git โ€บ git merge command
Git Merge From Branch Master Into Feature Branch [ 2026 ]
January 6, 2024 - Invoking the git merge command will merge the specified branch feature into the current branch, and weโ€™ll assume the main. Git uses different algorithms to automatically determine how to handle merging, depending on the situation.
๐ŸŒ
GitHub
docs.github.com โ€บ articles โ€บ about-pull-request-merges
Pull request merges - GitHub Docs
Instead of seeing all of a contributor's individual commits from a topic branch, the commits are combined into one commit and merged into the default branch. Pull requests with squashed commits are merged using the fast-forward option. To squash and merge pull requests, you must have write permissions in the repository, and the repository must allow squash merging. You can use squash and merge to create a more streamlined Git history in your repository.
๐ŸŒ
Varonis
varonis.com โ€บ blog โ€บ git-branching-and-merging
Git Branching and Merging: A Step-By-Step Guide
September 12, 2025 - Once you merge the hotfix branch, continue working on the feature1 branch. As you continue making commits on the feature1 branch, the commit history diverges. Git is unable to move the pointer to the latest commit like in a fast-forward commit. To bring the feature1 branch into the main branch, Git performs a three-way merge.
๐ŸŒ
Belev
belev.dev โ€บ git-merge-vs-rebase-to-keep-feature-branch-up-to-date
Git merge vs rebase to keep feature branch up to date | Martin Belev
May 25, 2020 - We can achieve this by either using merge or rebase to get the latest changes made in the master branch into our feature branch. ... Let's now look at an example using merge to keep our branch up to date. This is pretty simple example with a few commits in each branch:
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ git-merge
Git Merge Tutorial: A Comprehensive Guide with Examples | DataCamp
March 12, 2025 - A feature branch and the main branch diverge from a common base and are later combined into a single merge commit. Image by Author. Git merge takes all new commits from both branches, starting from their common base, and combines them into a single merge commit.
๐ŸŒ
FreeBSD
forums.freebsd.org โ€บ development โ€บ userland programming and scripting
Other - git: correct way to merge/pull commits/branches into master retaining history? | The FreeBSD Forums
September 4, 2024 - Merging then moves the pointer of the branch (e.g. master) forward to the commit the (diverged) branch points to, which automatically inherits all "parent commit" relationships, and because it is a direct descend it works without any intermediate "merge commit". Click to expand... Sounds right to me, yes! As far as I'm concerned, this "rebasing" workflow is most often the superior way to work with git. What I think makes it very nice is that you'll run into conflicts during rebase, which only affects the branch you work on, not the branch you want to "merge back" to.
๐ŸŒ
Better Stack
betterstack.com โ€บ community โ€บ questions โ€บ how-to-merge-multiple-commits-into-another-branch-as-single-squashed-commit
How Can I Merge Multiple Commits onto Another Branch as a Single Squashed Commit? | Better Stack Community
July 25, 2024 - ... Finally, you can delete the temporary branch if you no longer need it. ... git merge --squash temp-branch git commit -m "Merged commits from source-branch as a single squashed commit"