0

I am working on dev branch right now. Earlier, I created a featureX branch from dev branch and since then I've made 15 commits to dev branch. Now I want all those 15 commits in featureX branch, so that my featureX branch can also have all the work I have done in last week in dev branch.

I am super confused with rebase, rebase --onto, etc. commands. Should I be using one of these?

wcarhart
  • 2,685
  • 1
  • 23
  • 44
003
  • 197
  • 1
  • 12

1 Answers1

1

It sounds like there are three git commands that might be helpful: rebase, cherry-pick, and merge.

rebase

The easiest way to integrate the branches...is the merge command. It performs a three-way merge between the two latest branch snapshots...and the most recent common ancestor of the two..., creating a new snapshot (and commit).

However, there is another way: you can take the patch of the change that was introduced...and reapply it on top. In Git, this is called rebasing. With the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch.

In your example, you could do the following:

git checkout featureX
git rebase dev
# continue your development on the featureX branch

# if there are conflicts, resolve them, and then continue with
git rebase --skip

# when done with changes, do:
git checkout dev
git merge featureX

cherry-pick

Apply the changes introduced by some existing commits.

In your example, you could do the following:

git checkout dev
git cherry-pick ^HEAD dev

merge

Merge changes from one branch into another.

In your example, you could do the following:

git checkout featureX
git merge dev

All examples and excerpts are from the documentation:

Further reading:

Community
  • 1
  • 1
wcarhart
  • 2,685
  • 1
  • 23
  • 44
  • Thank for the well crafted answer. All these will help me to get the changes to ```featureX``` without effecting ```dev``` branch, right? and then I can continue working on ```dev``` branch, right? – 003 Sep 08 '19 at 01:14
  • @Ddp Yes, your changes in `featureX` won’t affect `dev`, unless you merge `featureX` back into `dev` – wcarhart Sep 08 '19 at 03:39