0

I've got a problem while working with github.

The problem is:

  1. I've created a repository.

  2. I've filled master branch but made a big mistake, so there's a big story what I don't need.

  3. Then I create a new branch (OhThisAmazingBranch), empty and began a normal project without problems.

  4. I need to delete master branch and make OhThisAmazingBranch as master.

How to do that? Is that even possible?

P.S. I am working using VS 2019

UPD. I tried advises what I've found before asking in here, they didn't work, so here I am.

UPD2. Thanks everybody for your answers, I'll try every one what's looks useful for me and let you know if it helped.

Claire
  • 91
  • 1
  • 12

4 Answers4

1

hard reset your master branch with "OhThisAmazingBranch"

git reset --hard OhThisAmazingBranch

Force push your new master branch

git push -f origin master

Voilà

0

Ideally you should not have to hack around your master branch in this way. Rather, if you don't like the initial direction set by the master branch, then perhaps just create a feature branch and move in the direction you want. That being said, if you really wanted to do this, you could try resetting master to the first commit locally, then amending the first commit:

# from local master
git reset --hard <first SHA-1 commit hash>
# make the code changes you want here
git commit --amend -m 'new first commit'
git push --force origin master

Note that the amend step is necessary to introduce the changes you want at the beginning of the master branch.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

If you're allowed and willing to make a destructive operation then you could try something like this:

  1. Checkout your local master branch. e.g. git checkout master
  2. Reset it to the last commit you want to keep. e.g. git reset --hard COMMIT_HASH
  3. Then force-push it to your remote. e.g. git push -f origin master

Now both your local and remote master branches are the same. You can branch from it and cherry-pick the commits from the other branch. (There may be conflicts though.)

customcommander
  • 17,580
  • 5
  • 58
  • 84
0

While the other answers mention how to recover your master branch, in case you wish to do exactly what you mention in the question, use the following steps:

  1. Change the default branch from master to OhThisAmazingBranch: This can be done in Settings > Branches and setting the default branch. More information here.
  2. Delete the master branch: This can be done by clicking the branch icon and then the delete option in front of the branch name. More information here.

You can then rename OhThisAmazingBranch if you wish to, which is described here.

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
  • 1
    This _may_ be a perfectly valid answer but I'm not sure why you think this is exactly what the author had in mind. GitHub is almost irrelevant here and the author isn't explicitly asking how to solve it through the GitHub web interface. – customcommander Jan 20 '20 at 13:23