Delete the old remote branch: $ git push origin -d -f Rename the current branch Push the new branch to create a new remote branch: $ git push origin ģ. If the branch exists on the remote Git server, continue to the next steps.Ģ. Of course, this only renames your copy of the branch. Rename the local branch: $ git branch -m Renaming a topic branch is useful if you have named a branch incorrectly or you want to use the same branch to switch between different bugs or tasks after merging the content into the main branch. With this article at OpenGenus, you must have the complete idea of how to delete the master branch of a Git repository.New Git articles Rename a branch using Git Delete the master branch using the same commands as in previous section.First, change the default branch in your repository settings in the service using web browser.Similar to GitHub, other services like GitLab and BitBucket also set master branch as the default branch and hence, if you need to delete it: OR, clone the repository locally, delete the master branch locally and push the changesĭelete master branch in GitLab / BitBucket repository.Using this, change the default branch to any other branch or select placeholder (if you do not have other branches and you need a dummy branch for now). You will set a dropdown menu for "Default branch".Then, click on "Branches" (on the left side vertical bar).Go to your repository in GitHub using a web browser.Following are the commands to change the default branch in GitHub: If you want to delete the master branch in a GitHub repository, you need to first change the default branch in the concerned repository and then, delete the master branch. This is because in GitHub, the master branch is set as the default branch and hence, cannot be deleted. When dealing with a Git repository hosted at GitHub, the commands in the previous section will not work directly. Delete master branch in GitHub repository You can delete the master branch now using the following commands: git push origin -d masterĬheck the detailed commands to delete a remote branch here. With this, we have made the master branch just a normal branch which you can delete as usual. Replace branch2 with the branch you want to be pointed to by HEAD. If the HEAD reference is the master branch, update the HEAD in your Git repository using the following command: git symbolic-ref HEAD refs/heads/ Use the following command to check the reference for HEAD: git symbolic-ref HEAD Delete master branch in local or remote repositoryįirst, we will check the references in your repository, check if HEAD reference is master and if so, we update it to another reference branch.įind the references in your Git repository using the following command: find ref The process of deleting a master branch either in local or remote repository will require to address these two points. If master branch is deleted, what will HEAD point to?.If master branch is deleted, there needs to be another active branch.The problem in deleting a master branch is: The HEAD of the Git repository points to this master branch. This is the branch the repository is checked in. In short, the command to delete a master branch is: git symbolic-ref HEAD refs/heads/Įvery Git repository has an active branch which by default is the master branch. It may seem unreasonable that one wants to delete a master branch but in reality, it is reasonable as master branch is just another branch with some special properties which can be transferred to other branches.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |