How to change from one feature branch to another?

Viewed 69

I am working on branch A cut from featA. So I was keeping A uptodate with featA. But there is another branch featB newly created and has slightly different commits than featA. Now I wanted to make my branch A uptodate with featB without featA changes. How can I resolve this considering I may get merge conflicts? Any suggestions would be very helpful.

3 Answers

try this

git checkout A
git fetch origin
git rebase origin/featB

Another way to do this,

git checkout A
git pull origin featA # pull update from `featA`
git pull origin featB # pull update from `featB`

Now branch A has all commits of featA and featB

It highly depends on your commit graph and what you want to include or not

Assuming you have

a <- b <- c <- d <- e   <<- featA
     ^         ^
      \         \- f    <<- A
       \- g             <<- featB

If it is what you want:

a <- b <- c <- d <- e   <<- featA
     ^
      \
       \- g             <<- featB
          ^
           \- f'        <<- A

You can simply do a

git rebase  --onto featB featA A

If you want you A to include a,b,c,d,f,g, you should do

git checkout A  # make sure you are at A
git merge featB

which will give you

a <- b <- c <- d <- e         <<- featA
     ^         ^
      \         \- f <- h     <<- A
       \               /        
        \-g <---------/       <<- featB
Related