If you get the error below, it may mean that someone else has already deleted the branch. You can also use this shorter command to delete a branch remotely: git push :įor example: git push origin :fix/authentication įor example: git push origin -delete fix/authentication Here's the command to delete a branch remotely: git push -delete. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The -d option will delete the branch only if it has already been pushed and merged with the remote branch. For example: git checkout mainįor example: git branch -d fix/authentication Git will not let you delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting. Once work is completed on a feature, it is often recommended to delete the branch. Repos often have a main branch for the main codebase and developers create other branches to work on different features. They are a great way to work on different features and fixes while isolating the new code from the main codebase. It is common for a Git repo to have different branches. You'll learn how to delete a Git brach locally and remotely in this article. Mouse over one of the merge commits: You'll see that it's called "Merge branch 'X' into Y", so you can see what the branch was named even if the black label is gone.In most cases, it is simple to delete a Git branch. Either way, the branch's commit history is preserved no story is lost. If you delete the branch, the black label disappears. If you don't delete the branch after merging, then the black label remains on the commit before the merge point. When you are "on a branch" and you make a commit, you add a dot to the commit history chain and move the relevant black label to your new dot.ĭiagonal arrows show where a branch is merged into another. "Creating a branch" means attaching a black label to a commit of your choice. "Deleting a branch" means removing a black label. The black-background labels are the "pointers" that represent active branches. The dots on the horizontal lines represent individual commits. The horizontal lines show the histories of parallel branches. If the branch on the remote is deleted then I lose a bit of the story of how the code got to that state don't I?Īs said, no story is lost when deleting a branch because only the pointer/reference to a commit is deleted, not the data itself. I want to see the branches when I look in the past. There is a page which describes the general GitHub workflow: Understanding the GitHub flow Notice also that this doesn't affect your local clone (you have to delete the branch manually). You can now update your fork on GitHub, pull from your fork, and finally delete the local branch (Git will warn you about deleting branches that have not been merged into master). Notice that the master branch on your fork is now behind master of the original project (because your branch got merged). Once merged, you can delete the branch from your fork, because the changes are now part of master in the original project (there is no reason to keep it). Then you can go to GitHub and open a pull request to ask the maintainer(s) of the original project to merge your changes (because you don't have write-access). When you add a branch, you can push it to your fork (because you have write-access). When you clone the fork, the fork becomes remote to your clone. On GitHub, when you fork a project, the original project becomes remote to your fork (you could even fork a fork if you wanted to.). Likewise, you can have as many branches of your own without having to push them to the remote (sometimes you can't because they are read-only). Git allows you to pull other branches if you want, but that is not mandatory. You'll notice that the clone - by default - only includes the master branch. You can even have multiple remote repositories if you wanted to. In Git, any repository can be remote. When you clone a Git repository, the source becomes remote to the clone. It doesn't matter if the remote is on your computer or on another server. This can indeed be confusing if you are used to centralized VCSs. I still am not sure I 100% understand the concept of local and remotes having totally different branches either!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |