DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 28

Cherry-picking a Commit from Feature Branch into Master

The Nautilus application development team needed to merge a specific commit from the feature branch into the master branch of the /opt/news.git repository. The required commit had the message “Update info.txt”. The task was to cherry-pick this commit into master and push the changes to the remote repository.

Steps Performed

1. Navigate to the repository

cd /usr/src/kodekloudrepos/news
Enter fullscreen mode Exit fullscreen mode

2. Identify the required commit

Listed commit history in the feature branch to find the hash of the commit with the message Update info.txt:

git log --oneline feature
Enter fullscreen mode Exit fullscreen mode

Example output:

a1b2c3d Update info.txt
f6e7g8h work in progress changes
1234abc initial commit
Enter fullscreen mode Exit fullscreen mode

The commit hash for Update info.txt was noted as a1b2c3d.

3. Switch to the master branch

git checkout master
Enter fullscreen mode Exit fullscreen mode

4. Cherry-pick the commit

Applied the specific commit from the feature branch to master:

git cherry-pick a1b2c3d
Enter fullscreen mode Exit fullscreen mode

This brought only the Update info.txt commit into the master branch without merging all feature branch changes.

5. Push changes to remote

git push origin master
Enter fullscreen mode Exit fullscreen mode

Outcome

  • The commit Update info.txt from feature was successfully merged into master.
  • The repository history remains clean, as only the required commit was cherry-picked.
  • Changes were pushed to the remote, ensuring the team can now access the updated master branch.

Top comments (0)