![]() An easy mnemonic clue for this option is to remember that when it comes to Git branches, “D” stands for delete. Circumstances will dictate which one you choose to use, but at this time it is a good idea to commit them to memory. D Force deletion of a branch.īelow, you will see these options in action. There are two important options for you to memorize when it comes to deleting branches in Git: -d Delete a branch, followed by the name of the branch. In this article, you’ll learn how to delete branches you no longer need. Some of these branches will get merged into the “master” branch while others may rot on the vein and never be used. But over time, your branches might start to add up. The branch functionality is one of the most important systems you can master with Git, and it will help you manage your projects with maximum efficiency. If you want more details, we have a separate tutorial on the topic.As you will likely recall from our introductory guide on everything Git, you can create discrete branches in your project, upon which you can make changes, test things, and work non-destructively, always reserving the option to “check out” other branches. Deleting a remote branchĭeleting a remote git branch is not the same as deleting the local ones. Now, you can see that the test-lhb branch is restored with its contents intact. ![]() So, in my case, if I want to restore the test-lhb branch, I would run the following command. Now, use the following syntax to restore the deleted branch. Using the same command (and output) as above, as you can see, SHA1 sum is provided at the end - which is d2ec7fe. When you delete a branch, Git shows the SHA1 sum of that branch. In case you want to undo the action, please make sure that you have the SHA1 sum of the branch you deleted. Well, let's say you deleted the wrong branch by mistake. So, when I want to forcefully delete a branch, I would run the following command: $ git branch -D test-lhbĪs you can see, the test-lhb branch is now deleted forcefully. ![]() When you are faced with this situation, and if you are sure about deleting said branch, use the -D flag instead of -d flag using the same syntax: git branch -D If you are sure you want to delete it, run 'git branch -D test-lhb'. If the commits in that branch are not pushed to a remote repository.īelow is an example of how it might look when deleting such a branch: $ git branch -d test-lhbĮrror: The branch 'test-lhb' is not fully merged.Either the commits in that branch are not merged with 'master' branch.So, when I want to delete the test-lhb branch, I would run the following command: $ git branch -d team-lhbīut, when the branch you are deleting has either one of the following conditions met, Git will not allow you to delete that branch with the -d flag. The easiest way to delete a Git branch is using the -d flag along with the git branch command and also specifying the branch name. This way, you get the exact branch names. The one with asterisk (*) is the current branch: $ git branch ![]() It shows the following two branches for me. To check which branch you are on and all the available local branches, use this command: git branch Your branch will always be the "master" branch (unless specified otherwise). Learn about deleting them in this one.ĭelete a branch with -d option of git branch command: git branch -dįorce delete a branch (if there are comments to the branch) with option -D: git branch -D In the previous article, you learned about creating branches in Git. Which, in turn helps you work with multiple people at once. It allows you to have multiple branches to isolate your code from the main branch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |