1/ The correct sequence is:
git branch -m old_branch new_branch # Rename branch locally
git push --set-upstream origin new_branch # Push the new branch, set local
branch to track the new remote
# go to GitHub and select new_branch as your default one
git push origin :old_branch # Delete the old branch
2/ Starting July 2020:
Links to deleted branches now redirect to the default branch
Previously, when branches were deleted on GitHub, any links that contained the old branch name broke across StackOverflow, email, Slack and other integrations.
Links to deleted branches now redirect to the default branch.
So, for example, the link https://github.com/dependabot/dependabot-core/blob/master/README.md will now redirect to an equivalent link on the default branch: https://github.com/dependabot/dependabot-core/blob/main/README.md.
This change only affects view links; other types of links (like edit links and blame links) don't redirect.
This change is the first of many changes GitHub is making to support projects and maintainers that want to rename their default branch.
To learn more about the changes we're making, see github/renaming
.
3/ Starting Jan. 2021
This is directly supported.
See "Renaming a branch in GitHub"
