How copy a commit from a branch to another in git?
Sometimes we have a commit in a branch that we want to move to another branch. For example I have created a repository with 3 branches and in each one I added a file:
In master branch there is a file named hello ; in branch_1 there are 2 files hello and hola ; in branch_2 there are also 2 files hello and ola .
Get fab’s stories in your inbox
Join Medium for free to get updates from this writer.
Now we want to see the commits create in each branch.
Each branch have the master commit and other commit where we added changes. In this example we want to move the commit 7a48fca from branch_2 to branch_1 . In simple words we want to apply the changes did in branch_2 in branch_1 . To do it, we could use the command cherry-pick like git cherry-pick commit-id-to-move :
Now in branch_1 we have 3 commits:
And also we have 3 files:
So we finished. If you want to know more about this command you could see the documentation in https://git-scm.com/docs/git-cherry-pick.






