79622152

Date: 2025-05-14 19:32:09
Score: 1
Natty:
Report link

In reference to the comment by https://stackoverflow.com/users/213191/peter-h-boling to the currently accepted answer, here are the additional steps needed to also rename a remote that is not e.g. on GitHub, i.e. does not provide an out-of-the-box option to rename and change the default on the remote:

4. instead of 4. of the currently accepted answer, let's push the local main to the remote:

git push -u origin main

5. the remote's "default" still is master, let's change it to main:

git symbolic-ref HEAD refs/heads/main

Alternatively, if you have access to the remote repo, the HEAD file can be modified directly to:

ref: refs/heads/main

6. finally let's delete master on remote:

git push origin --delete master

Note:

Depending on the environment, step 6. likely fails if attempted without 5., there likely is an error like "! [remote rejected] master (refusing to delete the current branch: refs/heads/master)". Changing the remotes "default" at 5. prevents this.

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: maettu_this