Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace branch completely with another branch

Tags:

git

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 found this other answer:

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.

like image 986
nick Avatar asked Jan 24 '26 13:01

nick


1 Answers

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).

like image 155
Gaël J Avatar answered Jan 26 '26 06:01

Gaël J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!