Say I have an existing branch B (if it makes a difference, it's remote).
I also have a branch A (either local or remote). I would like branch B to be exactly like A. If I understand correctly, merge doesn't make the branches identical, there still can be something in branch B that wasn't on branch A and it will remain there after doing git checkout B
followed by git merge A
. Do I understand correctly?
Of course, I can just delete branch B and create a new branch B from A. Is that the best way?
note just to clarify it: I want to keep branch B alive because of deployment configuration. If I delete and recreate I'll need to do another thing manually for deployment.
To make a merge, you check out some branch ( A in these cases) and then run git merge and give it at least one argument, typically another branch name like B . The merge command starts by turning the name into a commit ID. A branch name turns into the ID of the tip-most commit on the branch.
branch : add a --copy ( -c ) option to go with --move ( -m ) Add the ability to --copy a branch and its reflog and configuration, this uses the same underlying machinery as the --move ( -m ) option except the reflog and configuration is copied instead of being moved.
Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.
git keeps track of the history of development. Thus, to make a branch exactly like another branch, you just need to:
git checkout <branch B>
git reset --hard <branch A>
git push --force origin <branch B>
Of course, doing this you will lose the development history that was on branch B.
Sounds like you just want to rename branchB
.
git branch -m branchB new_name_for_branchB
git branch branchA branchB
Now new_name_for_branchB
refers to the same commit that branchB
used to, and branchB
now refers to the same commit as branchA
. The two branches A and B are still distinct, though.
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