0

I have a branch(created from master)(branch_a) with several commits and pushes. Now is there a way to include all these changes into a brand new branch(from Master)(branch_b) that I am about to create?

git checkout master
git checkout -b branch_a
Now in branch_a i do some work(x,y,z)
git add .
git commit -m 
git push

And now,

git checkout master
git checkout -b branch_b
Now in branch_b

How can I include my work(x,y,z) into the branch_b and then commit and push it ?

Thanks

oyeesh
  • 551
  • 9
  • 21

3 Answers3

1

If you need just x, y, z commits from branch_a (on top of master) then create a new branch from that branch. It will be same as branch_a.

If branch_a contains some other work that you don't want then you have few posibilities.

  • create new branch from master and cherry-pick commits from branch_a

  • create new branch from branch_a and do interactive rebase on top of (historically) first commit that you need and eject later commits that you dont need (this will rewrite your history - sha1 hashes)

Ask for details if you have problems with executing this tasks or refer to other answers about cherry-pick and interactive rebase.

Zildyan
  • 1,261
  • 9
  • 11
0

The quickest way is to just create branch_b at branch_a:

$ git checkout -b branch_b branch_a

This is short-hand for the two commands

$ git checkout branch_a
$ git checkout -b branch_b

I find the first useful since it is less typing.

Note that master is not special. It is just a branch name. This means that anywhere you see master in any documentation or example, you replace it with any other branch.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
0

How can I include my work(x,y,z) into the branch_b and then commit and push it ?

If all you need is get all changes from branch_a and put them on branch_b. You could create the second brach FROM branch_a.

Like:

git checkout -b branch_b branch_a  

This will create a brand new branc_b from branch_a and automatically switch to branch_b. Just commit and push later.

PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90