Git-how to overwrite one branch with another branch

270 阅读1分钟

In some cases, we want to overwrite branch A with branch B, especially when there are too many conflicts after long time working or someone's code has ruined the branch A. Here is the method:

// firstly, checkout to branch A 
git checkout branchA 
// then reset origin 
git reset --hard origin/branchB 
// push to remote forcefully 
git push -f 

So simple, now BranchA is clean again.