I have opened a Git repository with readme file in Github, and then use below to push local code to this repository
git push origin master
It shows two branchs: main and master, but with git branch, it only shows main branch
$ git branch
* main
As main branch is empty, I use below to force the commit to main
git push --force origin main
Now there are two same branches: main and master in the repository, but still with git branch, only show *main.
When I clicked the master, it shows:
This branch is even with main.
I use below to delete master, but the error as below:
$ git push main --delete origin/master
fatal: 'main' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What should I do now to delete one of them?
And why the main not replaced by the master?
Later should I use git push origin main instead of master to push changes?
Thanks.
If you want to do this from the UI, you can go to the branches section of the repository and delete the branch you want to delete.
There is delete icon on right most side of a branch name.
If you want to do on git:
git push origin --delete master
The reason why you see only main
in your local setup is, when you clone any repo only the default branch is cloned. For having other branch on git you have to fetch
and pull
the other branch.
For pushing changes after deleting master, you can use git push origin main
to push changes in main branch.