Ad

How To Remove Remotes/origin/master After Move To Main?

- 1 answer

The project we are using had its master branch moved to main, on GitLab for reasons of consistency.

Locally I had renamed the master branch to main:

git branch -m master main

This seemed to be enough until I accidentally did git checkout master and then it recreated the master branch. Doing a git branch -a, I see I now have the following two remotes (in addition to my other ones):

  remotes/origin/main
  remotes/origin/master

How do a tell the local repo to forget about remotes/origin/master, to avoid accidentally recreating master, when I mean to switch to the main branch?

Ad

Answer

If the git fetch --prune does not work, it could mean the master branch is still on GitLab remote repository side (it could have been pushed by mistake by another developer who also checkout the wrong local master branch first)

In any case, once GitLab repository is clean, you can also add a pre-commit hook in order to prevent any future accidental checkout of the wrong branch.

Ad
source: stackoverflow.com
Ad