0 votes
1 view
in Devops and Agile by (20k 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 (28.4k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...