Copy changes from one branch to another
Solution 1:
git checkout BranchB
git merge BranchA
This is all if you intend to not merge your changes back to master. Generally it is a good practice to merge all your changes back to master, and create new branches off of that.
Also, after the merge command, you will have some conflicts, which you will have to edit manually and fix.
Make sure you are in the branch where you want to copy all the changes to. git merge
will take the branch you specify and merge it with the branch you are currently in.
Solution 2:
Instead of merge, as others suggested, you can rebase one branch onto another:
git checkout BranchB
git rebase BranchA
This takes BranchB
and rebases it onto BranchA
, which effectively looks like BranchB
was branched from BranchA
, not master
.
Solution 3:
This is 2 step process
- git checkout BranchB ( destination branch is BranchB, so we need the head on this branch)
- git merge BranchA (it will merge BranchB with BranchA. Here you have merged code in branch B)
If you want to push your branch code to remote repo then do
- git push origin master (it will push your BranchB code to remote repo)