gitgit-branchbranching-and-merging

Copy changes from one branch to another


I have a branch named BranchA from master. I have some changes in BranchA (I am not going to merge changes from BranchA to master).

Now I have created another branch from master named BranchB.

How can I copy the changes from BranchA to BranchB?


Solution

  • 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.