Replace branch completely with another branch


I have 3 branches: development, qa, and staging. I have almost the same code in both development and qa, so making a pr from development to qa doesn’t yield too many changes (and or conflicts).

But now I have a move all the stuff from qa to staging. And qa code is practically completely different and new from staging, so what’s the best option? I searched and saw this:

git checkout qa
git merge -s ours staging
git checkout staging
git merge qa

Is this a good idea for my case? Thanks in advance!

EDIT: I don’t want to lose all the commits from staging branch.


If you want to "completely replace", I’ll go with git reset:

git checkout staging
git reset origin/qa --hard

This will make staging have the exact same content as qa but this will "erase" commits that may have been done on staging (the commits won’t be deleted yet but they won’t be visible in the history of staging anymore).

Answered By – Gaël J

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published