Wednesday, November 29, 2017

How push or sync commits to a different branch

Let’s say we have created a branch yesterday and committed some changes to master branch.
If we want to make both the branches even.
  1. Option 1 -> is to delete and recreate the branch again from master.
  2. Option 2 -> checkout to master branch and run below command.
    git push origin master:<new_branch>
All the commits are identified by a unique ID.So we don’t need to mention the parent branch of the commit if we know its ID.So, If we want to add only a specific commit, then run below command from the target branch checked out.
git checkout -b new_branch origin/new_branch -> If branch never checked out locally.
git checkout new_branch -> If already checked out locally.
git cherry-pick <commit-ID>
Reference: https://www.devroom.io/2010/06/10/cherry-picking-specific-commits-from-another-branch/

No comments:

Post a Comment