Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

I have two branches in my Git repository:

master

seotweaks (created originally from master)

I created seotweaks with the intention of quickly merging it back into master. However, that was three months ago and the code in this branch is 13 versions ahead of master.

It has effectively become our working master branch as all the code in master is more or less obsolete now.

Very bad practice I know, lesson learned.

Do you know how I can replace all of the contents of the master branch with those in seotweaks?

I could just delete everything in master and merge, but this does not feel like best practice.

1 Answer

0 votes
by (50.2k points)

To replace a master branch in git entirely from a branch we are going to use a merge strategy known as ‘ours’.

Let’s see how this strategy works 

For that, we have a master and child branch

First, checkout child branch

Sudo git checkout child

Now merge using ‘ours’

 Sudo git merge -s master

-s is a shortcut for -strategy

Goto master

Sudo git checkout master

Sudo git merge child

Then the result should be your master is now a child.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...