I have two branches, email
and staging
. staging
is the latest one and I no longer need the old changes in email
branch, y
Other answers looked incomplete.
I have tried below in full, and it worked fine.
NOTE:
1. Make a copy of your repository before you try below, to be on safe side.
Details:
1. All development happens in dev branch
2. qa branch is just the same copy of dev
3. Time to time, dev code needs to be moved/overwrite to qa branch
so we need to overwrite qa branch, from dev branch
Part 1:
With below commands, old qa has been updated to newer dev:
git checkout dev
git merge -s ours qa
git checkout qa
git merge dev
git push
Automatic comment for last push gives below:
// Output:
// *<MYNAME> Merge branch 'qa' into dev,*
This comment looks reverse, because above sequence also looks reverse
Part 2:
Below are unexpected, new local commits in dev, the unnecessary ones
so, we need to throw away, and make dev untouched.
git checkout dev
// Output:
// Switched to branch 'dev'
// Your branch is ahead of 'origin/dev' by 15 commits.
// (use "git push" to publish your local commits)
git reset --hard origin/dev
// Now we threw away the unexpected commits
Part 3:
Verify everything is as expected:
git status
// Output:
// *On branch dev
// Your branch is up-to-date with 'origin/dev'.
// nothing to commit, working tree clean*
That's all.
1. old qa is now overwritten by new dev branch code
2. local is clean (remote origin/dev is untouched)