Search⌘ K
AI Features

Attempting to Apply Cherry-Pick

Explore the process of cherry-picking a commit from one branch to another in Git. Understand how conflicts trigger a three-way merge involving the source, target, and common ancestor commits, and learn how to handle these merges effectively.

A simple branched repository

This should be fairly routine by now. You’re going to set up a Git repository with two branches and some simple changes in them. Once that’s done, you’re going to try to cherry-pick a change from the abranch branch and apply it to the master branch.

1	mkdir lgthw_patch_and_apply
2	cd lgthw_patch_and_apply
3	git init
4	touch afile
5	git add afile
6	git commit -m 'afile added'
7	echo First change, on master >> afile
8	git commit -am 'First change, on master added'
9	git branch abranch
10	echo Second change, on master >> afile
11	git commit -am 'Second change, on master added'
12	git checkout abranch
13	echo First change, on abranch >> afile
14	git commit -am 'First change, on abranch added'
15	echo Second change, on abranch >>
...