Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.

Then, tens of commits later, I realized the branch is in much better state than the master, so I want the branch to "become" the master and disregard the changes on master.

I cannot merge it, because I don't want to keep the changes on master. What should I do?

Extra: In this case, the 'old' master has already been push-ed to another repository such as GitHub. How does this change things?

1 Answer

0 votes
by (27.5k points)

Before performing this, make sure everything is pushed up to your remote GitHub repository:

git checkout master

Then to overwrite "master" with "new_branch":

git reset --hard new_branch

Now force the push to your remote repository:

git push -f origin master

Browse Categories

...