Cherry-Picking Commits To a Remote Branch

  1. Identify the commits that you want to merge with the target. What you are looking for is the commit hashes. You can find them in TFS, or you can use
    $ git log --oneline
    
    If you know that every commit you’re looking for has the string 188380:User Story in it, then you can refine your search with something like the following:
    $ git log --oneline | grep "188380:User Story"
    
    In this example you might get a result like
    e2f13ae5 188380:User Story: Push Notification with blocked browser settings
    b3b65110 188380:User Story: Push Notification with blocked browser settings
    5a1288bc 188380:User Story: Push Notification with blocked browser settings
    
    You are looking for the commit hashes:
    e2f13ae5
    b3b65110
    5a1288bc
    
  2. Create a new branch based off your target branch.
    $ git checkout -b Trav-Cherry-Pick origin/Master
    
  3. Cherry pick your commits from the bottom of the list upwards:
    $ git cherry-pick 5a1288bc
    $ git cherry-pick b3b65110
    $ git cherry-pick e2f13ae5
    
  4. If you get any merge conflicts during the cherry-picking then fix them as they occur.
  5. Push your changes to a new remote branch.
    $ git push -u origin Trav-Cherry-Pick
    
  6. Finally, use GitHub or GitLab to create a pull request to merge your new remote cherry-pick branch with your remote target branch.


Categories: Development, Git

Tags: , ,

Leave a comment