How can I overwrite, not merge, one remote branch into another branch?
Solution 1
You can simple delete staging
and re-create it based on beta
:
git branch -D staging
git checkout beta
git branch staging
Solution 2
If you don't care about the old history of staging
, you can just recreate it:
git checkout beta
git branch -f staging
If you do care about the old history of staging
, then things get more fun:
git checkout staging # First, merge beta into staging so we have
git merge -s theirs beta # a merge commit to work with.
git checkout beta # Then, flip back to beta's version of the files
git reset --soft staging # Then we go back to the merge commit SHA, but keep
# the actual files and index as they were in beta
git commit --amend # Finally, update the merge commit to match the
# files and index as they were in beta.
Solution 3
I suggest you just rename it in case you change your mind.
git branch -m staging staging_oops
git checkout beta
git branch staging
If you really can't stand having that extra branch around:
git branch -D staging_oops
Trip
I program Ruby, C#, iOS, Node, and Augmented Reality for Unity3D. I write PostgreSQL, mySQL, SQLite, and MongoDB. I use Heroku, Amazon, Microsoft Azure. Creator of the Yoga Sutras App, Braidio Mobile, and Braidio. In my spare time, I teach Ashtanga Yoga. elephant trip AT gmail DOT com #happyToHelp
Updated on May 17, 2020Comments
-
Trip about 4 years
I have two branches. Staging and Beta. Staging has code in it ( including files ), that I do not want at all. How can I make Beta completely overwrite Staging, so that none of those files or code are merged from Staging into Beta.
I see some people recommend doing this :
git checkout staging git merge -s ours beta
But I don't believe the pre-existing files would be a "code conflict" and therefore would not be removed. Am I wrong? If I'm right, how would I accomplish this?