1

I've been working on a forked branch "forkedBranch" and made many updates to my app. When I was happy with the updates, I went back to my master branch (git checkout master) and merged my forkedBranch (git merge forkedBranch). Unfortunately, the master branch has lots of problems with it that weren't present in forkedBranch.

The app is too complicated for me to want to go through and find all the bugs. Is there a way to make my master branch identical to forkedBranch to save me the hassle?

Adil B
  • 14,635
  • 11
  • 60
  • 78
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71

1 Answers1

1

If you're absolutely certain you don't need the master branch or any of its old commits:

  1. git branch --delete master && git push origin -delete master - delete the master branch locally and on origin
  2. git checkout forkedBranch && git pull origin forkedBranch - pull down the latest forkedBranch from origin
  3. git checkout -b master && git push origin master - recreate the master branch locally from the latest commit of forkedBranch, and push it up to origin
Adil B
  • 14,635
  • 11
  • 60
  • 78
  • Thanks! What if I want to keep the master branch history? would there be an alternative? – JimmyTheCode Jan 12 '21 at 08:04
  • 1
    If you need the `master` branch's history, run these commands first to create and push a backup branch to `origin`: `git checkout master && git pull origin master` then `git checkout -b backup/master && git push origin backup/master`. This will create a branch named `backup/master` that contains all of the commit history of `master`. – Adil B Jan 12 '21 at 14:25