16

I had created a remote repository in Github and pushed my project into that remote repository. After pushing it, a new branch is created master and now I have two branches main and master. The default branch is main which shouldn't be. At the time of the creation of the remote repository, I have added a Readme.md file maybe because of that main branch is created in the first place. Could you correct me here?

As of now, I have two branches, and I changed the default branch to master. For the main branch, it is showing as main had recent pushes 43 minutes ago and compare & pull request button. When I clicked the button it is showing as below.

When the main branch is created, Is it because of adding Readme.md file? How can I do a pull request as I am developing a small project alone? Need some guidance on that. enter image description here

David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
Subrato Pattanaik
  • 5,331
  • 6
  • 21
  • 52
  • 5
    Make `master` the default branch and delete `main`. – Guy Incognito Oct 12 '20 at 13:29
  • 1
    I mentioned already that I changed the default branch to master. I want to do some hands-on like creating a new branch and then merging that branch to master branch. how can I do that? – Subrato Pattanaik Oct 12 '20 at 13:33
  • 1
    I know it sounds stupid. could you provide me some tips like is it okay to merge one different branch to master branch without pulling requests? there is a lot to read I know could you help me with this particular concern. – Subrato Pattanaik Oct 12 '20 at 13:39
  • You don't need to do pull requests if you're the only one working on the repository. – Guy Incognito Oct 12 '20 at 14:17
  • 1
    If a personal project's small enough and your work is linear, committing straight to master can be a valid option – jv-dev May 26 '22 at 20:00

1 Answers1

18

Recently, GitHub has decided to change the default branch upon creating a new repo to main.

If you don't have any commits in main and you don`t need it, just delete that branch.

The screenshot you posted shows that there isn't anything to compare between the two branches and since you already made master the default, instead of main, you then don't really need main.

If you need to delete main there are many ways, either through the GitHub UI or command line (related).

Edit

GitHub now provides a setting that allows you to change the name of the default branch to every repository through https://github.com/settings/repositories. Here you can revert back to "master" as your default branch name.

mnestorov
  • 4,116
  • 2
  • 14
  • 24
  • 1
    Is it okay to merge one different branch to the master branch without pulling requests? I want to do some hands-on on that. Can you provide me some useful links for that? – Subrato Pattanaik Oct 12 '20 at 13:43
  • 1
    @SubratoPatnaik you can merge a branch without a pull request. You can do that locally on your machine. Here are resources ([1](https://www.atlassian.com/git/tutorials/using-branches/git-merge), [2](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)). Merging branches without a pull requests has many valid scenarios (but mostly when you are working alone) – mnestorov Oct 12 '20 at 13:46
  • 1
    one more question when I do `git branch -a`, two branches appear `master` and `remotes/origin/master` branch. There is no `main`. Then how could I delete that main branch? I changed the default branch to master. – Subrato Pattanaik Oct 12 '20 at 13:52
  • 1
    On github, go to your branches (click the branches icon) and there you should see the two branches and there will be a `trash` icon for the `main` branch. If you can't get around doing that. Then you need to `fetch` your `main` branch and then delete it locally and remotely. – mnestorov Oct 12 '20 at 13:54
  • 5
    GitHub now also has a settings page which lets you configure the default branch back to `master` like everyone in the universe is accustomed to having it. This way you you don’t have to suffer with conflicts between convention in your git CLI-tools and GitHub. https://github.com/settings/repositories – Jostein Kjønigsen Dec 14 '20 at 21:37