NatLibFi/Annif

Switch default git branch to main

juhoinkinen opened this issue ยท 5 comments

Nowdays the default branch of a new GitHub repository is named main instead of master, and many existing projects have renamed the default branch to main.

According to GitHub documentation the basic rename process should be quite straightforward. When a branch (master) is renamed in the GitHub web UI, automation re-targets all open PRs, sets up URL redirects etc..

However, the default branch can also be changed to an existing branch. This gives the opportunity to cleanly get rid of the two erroneously pushed commits (this and this) to master and their reverts by first branching the main from master at the point before the erroneous commits. Apparently changing the default branch does not automatically retarget PRs and do other changes what renaming would do.

But as @osma suggested, lets do the rename, and just drop the erroneous commits before.

Steps:

  • Reset master to the last good commit (Merge pull request #677) and force-push
  • In GitHub UI rename the default branch to main
  • Update local repository clones
  • Update references in GitHub Actions and documentation (CONTRIBUTING.md, README.md), maybe via a PR
  • Update references of master in Wiki (if necessary, the automatically created redirects may be enough)

I did locally

git reset --hard eb437a820c7140568d0d6f4fcc434925d5fe5316
git log  # double checking the reset was to correct commit
git push --force-with-lease  # before needed to switch off branch protection of master

Then renamed the default branch to main in GitHub UI, and I was shown the commands to update local clones:

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

References to master updated in #680. In Wiki the master -> main redirection in links works, so there is no need updates in there.

So everything else should be working as previously, but CodeBeat analysis got confused: the checks show
image

and I cannot find a way to change the target branch in CodeBeat project/account, I think I don't have the permissions for that.

osma commented

I had to recreate the NatLibFi/Annif project in Codebeat and delete the old one, as it wasn't possible to change the branch directly. I changed the badge in 3d44c00 so it refers to the new project.

Osma changed the branch also for the Scrutinizer analysis, so now (again) everything for this seems to be done, I close this.

Still one update was needed: the "latest" version of ReadTheDocs documetation was no following the new main branch before I switched the default branch (in Advanced Setttings) from ------ to main.