Copy one commit to another branch with cherry-pick

Description: The branch develop has an unfinished feature and a bug fix. Bring only the bug fix commit to main.

Hint:

  • Find the commit with git log, then use git cherry-pick with its name.

Solution

Terminal output

$ git log –oneline develop
0bbe41e (develop) Fix header bug
c03680a Add feature (not ready)
1e3d759 (HEAD -> main) Add home
$ git cherry-pick develop
[main 97e3b7d] Fix header bug
Date: Sat Jan 10 11:31:00 2026 +0000
1 file changed, 1 insertion(+)
create mode 100644 fix.txt
$ git log –oneline
97e3b7d (HEAD -> main) Fix header bug
1e3d759 Add home
$ ls
fix.txt
home.txt

How it works

  • The fix is the latest commit of develop, so we can use the branch name. Otherwise use the hash.
  • Only fix.txt came to main. The unfinished feature.txt did not.

Read Git Cherry Pick.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.