Rename branch on github website?

爷,独闯天下 提交于 2019-11-28 19:42:29

问题


I don't know how to run command line stuff, well I just don't have environment.

So I'm trying to rename a branch on the github website. It was default named to "patch-1".

Is it possible to rename this on the site?


回答1:


I think you can, just create a new branch with the new name, and delete the old one on github.

More detail you can see here.




回答2:


I just did it without downloading any code to my laptop only using github site.
The solution looks the same as @swcool, but I want to add about default branch.
In my case, the name of renaming branch did not exist.

  1. Change the default branch (to the old branch you want to rename)

  2. Create a new branch (with a new new name)

    This action will copy all the contents of the default branch(the branch with old name) to the new branch(with a new name). At this time, you have two branches with the same code.

  3. Change the default branch. (to the new one with new name)

  4. Delete the old branch




回答3:


It is not possible to rename a branch from the Github website. You will need to do 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




回答4:


If you don't want to install Git, clone 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 old one is:

    POST /repos/:owner/:repo/git/refs
    
    {
      "ref": "refs/heads/newBranchName",
      "sha": "<SHA1 of old branch>"
    }
    
  • delete the old branch:

    DELETE /repos/:owner/:repo/git/refs/heads/oldBranchName
    

That way, you will have "renamed" (create+delete) the branch without having git locally.

And, as commented by user3533716 below, use the GitHub API for listing branches to get those branch SHA1:

GET /repos/:owner/:repo/branches


来源:https://stackoverflow.com/questions/23850608/rename-branch-on-github-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!