Question

I have a "master" branch and a "master new" branch. The "master new" is a result of a mistake that was needed to be fixed quickly. I know it is a very bad practice to do that but thats were I am now. For a while now I have been working as if as the "master new" is my master branch, opening branches from it etc. My question is if there is a safe and easy way to make the "master" branch identical to the "master new" branch so I can start working with it and stop working from the "master new" branch?

Was it helpful?

Solution

Follow the below steps -

1) Delete the master branch from local as well as remote

2) Stay on master new branch and create new branch git branch master

3) Then run git checkout master This will clone all your code in master new branch to the newly created master branch

4) Now you can safely delete master new branch.

OTHER TIPS

If you haven't push either branches, you can simply drop master, and rename master_new into master.

git checkout master
git reset --hard master_new
git branch -d master_new

But if you have pushed master already, then you could merge master into master_new (keeping master_new unchanged)

git checkout master_new
git merge -s ours master

Than merge master_new back to master

git checkout master
git merge master_new
git branch -d master_new<
git push

That second solution wouldn't rewrite master's history, and allow you to share its new content safely with other users depending on the upstream repo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top