2

I want to rename branch from 'master' to 'introduction'. I found different links,but got me confused. Any help?

I tried this,but it didn't work.

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 
7
  • Possible duplicate of Renaming a branch in github Commented Dec 12, 2016 at 15:29
  • 1
    @Dario how would that help? He did exactly what the accepted answer suggests but didn't have success. Commented Dec 12, 2016 at 15:35
  • @Theo what does "didn't work" mean? Did you get some error message? Commented Dec 12, 2016 at 15:35
  • @Vampire. I got to my github and I see the master branch. it is not renamed. Commented Dec 12, 2016 at 15:36
  • 1
    But did you get any errors when issuing those commands? Maybe you have to change the default branch on GitHub for this to work properly Commented Dec 12, 2016 at 15:38

2 Answers 2

3

Go to https://github.com/<user>/<project>/settings/branches and change the default branch to being not the one you want to delete, then try again. You cannot delete the default branch in GitHub.

Sign up to request clarification or add additional context in comments.

2 Comments

Cool. I can now see the introduction branch! Thanks for that. However,I believe that there should be a way to delete the master branch. I mean from the terminal(gitbash in my case).
Not as long as it is configured as the default branch in GitHub. GitHub does not allow to remove the default that is in use of course. ;-)
1

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"

rename branch dialog

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.