Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite everything in master with another branch in git

Tags:

git

I have a very out of date master branch in a git repository.

All of my work has been done in another branch.

What is the best way to merge the two?

I don't care about anything in master, it is way out of date.

like image 847
Zuriar Avatar asked Apr 25 '15 20:04

Zuriar


People also ask

How do I overwrite git master?

Using the -f flag, your previous master is completely overwritten with develop , including its history.

Will git merge master overwrite my changes?

Usually git does not overwrite anything during merge.


2 Answers

If you are fine with losing the history of your master branch you just let master point to the head of your current branch (your don't "overwrite" master - the branch - per se):

git checkout yourotherbranch
git branch -D master
git checkout -b master

Of course if you have a remote clone, you'll then have to

git push -f origin master 

Nota bene: this specifically applies to replacing the whole of your master branch and throwing the old master away as the title suggests. Otherwise, you should be fine with git merge master --strategy=ours.

like image 192
Tobia Tesan Avatar answered Oct 18 '22 20:10

Tobia Tesan


Let's assume your work is in a branch called dev:

git checkout dev 
git merge --strategy=ours master
git checkout master 
git merge dev

The merge option --strategy=ours is meant to be used to supersede old development history of side branches (quote).

like image 28
Яois Avatar answered Oct 18 '22 20:10

Яois