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
?
The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch.
You could use git checkout from the branch you want to transfer the changes to: git checkout <branch name> . That will change all files to match the version in the desired branch. Then you can commit, change, discard whatever you want.
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.
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
.
This is 2 step process
If you want to push your branch code to remote repo then do
Copy content of BranchA into BranchB
git checkout BranchA
git pull origin BranchB
git push -u origin BranchA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With