[ACCEPTED]-How do I rename branch on the GitHub website?-rename
I just did it without downloading any code 10 to my laptop and using only the GitHub site.
The 9 solution looks the same as @swcool’s, but I want to add about 8 the default branch.
In my case, the name 7 of the renaming branch did not exist.
Change the default branch (to the old branch you want to rename)
Create a new branch (with a new name)
This 6 action will copy all the contents of the 5 default branch (the branch with the old 4 name) to the new branch (with a new name). At 3 this time, you have two branches with the 2 same code.
Change the default branch (to 1 the new one with a new name)
I think you can, just create a new branch 2 with the new name, and delete the old one 1 on github.
More detail you can see here.
It is not possible to rename a branch from 2 the Github website. You will need to do 1 the following -
Setup your Git Environment
Follow this - https://help.github.com/articles/set-up-git
Rename branch locally & on Github
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
If you don't want to install Git, clone 5 the repo, rename the branch locally and push it back to GitHub, you can use the GitHub API for references:
create a new branch where the 4 old one is:
POST /repos/:owner/:repo/git/refs { "ref": "refs/heads/newBranchName", "sha": "<SHA1 of old branch>" }
-
DELETE /repos/:owner/:repo/git/refs/heads/oldBranchName
That way, you will have "renamed" (create+delete) the 3 branch without having git locally.
And, as 2 commented by user3533716 below, use the GitHub API for listing branches to get those branch 1 SHA1:
GET /repos/:owner/:repo/branches
Since Jan., 19th 2021, you now can rename 20 a branch directly on github.com:
Support for renaming an existing branch:
You can 19 now rename any branch, including the default 18 branch, from the web.
If you've been waiting 17 to rename your default branch from
master
tomain
, we 16 now recommend doing so using this feature.When 15 a branch is renamed:
- Open pull requests and draft releases targeting the renamed branch will be retargeted automatically
- Branch protection rules that explicitly reference the renamed branch will be updated
Note: admin permissions 14 are required to rename the default branch, but 13 write permissions are sufficient to rename 12 other branches.
To help make the change as 11 seamless as possible for users:
- We'll show a notice to contributors, maintainers, and admins on the repository homepage with instructions for updating their local repository
- Web requests to the old branch will be redirected
- A "moved permanently" HTTP response will be returned to REST API calls
- An informational message will be displayed to Git command line users that push to the old branch
This change 10 is one of many changes GitHub is making 9 to support projects and maintainers that 8 want to rename their default branch.
Branch 7 names will not change unless the maintainer 6 explicitly makes the change, however this 5 new rename functionality should dramatically 4 reduce the disruption to projects who do 3 want to change branch names.
To learn more 2 about the change we've made, see github/renaming.
To learn 1 more, see Renaming a branch.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.