Skip to content

Cherry-Picking a Specific Commit

Cherry-picking allows you to select a single commit from one branch (or repository) and apply it to your branch.

1. Add the remote repository

Add the remote repository from which you want to cherry-pick the commit.

Example
git remote add <remote-name> https://github.com/username/repo.git
  • Replace remote-name with the branch name.
  • Replace username/repo with the username and repository you want to pull from.

2. Fetch the latest changes from the remote

Example
git fetch <remote-name>

3. Find the commit hash

You need to know the commit hash you want to cherry-pick. You can find the hash in the other repository's commit history.

4. Cherry-pick the commit

Example
git cherry-pick <commit-hash>

5. Resolve conflicts

If there are any merge conflicts, Git will prompt you to resolve them.

6. Push the changes

After cherry-picking the commit and resolving conflicts, push the changes to your repository.

Example
git push origin <branch-name>
  • Replace branch-name with your actual branch name (e.g., master).