Change the default branch of your GitHub repositories, from inside RStudio.
You can install the development version of branchMover from GitHub with:
# install.packages("devtools")
devtools::install_github("gadenbuie/branchMover")
The app uses the usethis and gh packages. You need to configure gh with a Personal Access Token to be able to authenticate with the GitHub API. Read more about setting up a PAT in one of these places:
- Managing Git(Hub) Credentials usethis article
- Personal access token for HTTPS guidance form Happy Git and GitHub for the useR
- Managing Personal Access Tokens gh article
Then, in RStudio, run the app with:
branchMover::app()
If you’d like to explore or reconfigure the default branch of
repositories that you manage in other organizations, provide app()
with the user or organization name. Branch Mover will tell you how many
repos you have access to in the organization and it won’t let you update
branch names for repos where you don’t have admin permissions.
branchMover::app("rstudio-education")
#> ℹ @rstudio-education has 57 total repositories (including forks)
#> • 57 public repos
#> • 0 private repos
#> ℹ 57 non-fork repositories have the following default branches:
#> x master: 51 repos
#> ✓ main: 6 repos
#> ℹ You have admin rights on 1 repo
branchMover changes the default branch on GitHub and creates an issue announcing the change. If everything works, the issue is closed and instructions on how to update local copies of the repo are added to the issue.
Unfortunately, branchMover doesn’t update the default branch in your local copies of your repos. Thankfully, this is relatively pain-free with the usethis::git_default_branch_rediscover() function, added in usethis version 2.1.2.
The tidyverse article Renaming the default branch by Jenny Bryan provides a lot more detail about what’s going on behind the scenes.