Git: Merge Specific Commit from Another Branch to Main Branch

Let’s say that in your git repository, you have a master branch and an experimental branch. You’ve fixed a bug on file A on the experimental branch and you would like to commit that fix to the master branch. This is possible using the git cherry-pick command.

First, switch to the experimental branch and execute git log. Take note of the ID of the commit you’d like to merge into the master branch. Now switch to the master branch and use the command git cherry-pick ID where ID is the ID of the commit you noted earlier. This will merge the selected commit into the master branch.