I would like to push all the changes in one branch to another branch (existing branch) without merging.
For the example, consider two branches branch1 to branch2. Both branch1 and branch2 track origin/branch1 and origin/branch2 respectively.
Branch1 has commits A,B,C,D,E,F Branch2 has commits A,B,D,F
I would like to make Branch2 exactly like branch1. Cherry-picking and merging would give conflict which i dont wanna spend time resolving, because all i am trying to do is, blindly replicating branch1 into branch2.
I am able to do this by
git checkout branch1 # Moves to branch1
git push origin :branch2 # Deletes remote branch origin/branch2
git branch -d branch2 # Deletes the local copy of this branch
git pull
git push origin HEAD:branch2 # Creates new branch in remote repository from the HEAD at local branch branch1
Is there a better way of doing this through some --force options in merge commands. I dont want to delete the branch everytime just to create a new branch with the same name.
Thanks
git switch branch1
git pull
git push origin branch1:branch2 --force-with-lease #assume the remote name is origin
git branch -f branch2 origin/branch2 #reset the local branch branch2
git checkout branchA
git merge -X theirs branchB
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