Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k 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 a 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 in 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 (50.2k points)

Just go through the following commands that will help you to make current git branch as a master branch

git checkout better_branch        # checkout to the branch

git merge --strategy=ours --no-commit master    #keep the content of this branch, record a merge 

git checkout master            #  It will take you back to the master

git merge better_branch             # fast-forward master up to a theme

git commit -m”message”    # for better understanding gives the message about what you have done.

This will allow you to make the current branch as a master branch.

Browse Categories