Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove remotes/origin/master after move to main?

Tags:

git

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?

like image 893
Andre M Avatar asked Oct 25 '25 17:10

Andre M


1 Answers

First step would be to try:

git fetch --prune

If that 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.

like image 89
VonC Avatar answered Oct 27 '25 08:10

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!