And a new branch lets you do this without affecting the main code in any way. You might create a branch to edit it to make changes, to add a new feature, or to write a test when you're trying to fix a bug. When working on a big project, there is the main repository with all the code, often called main or master.īranching allows you to create new, independent versions of the original main working project. Git branches are a snapshot of a project and its changes, from a specific point in time. In this article, you will learn the basics about how to remove local and remote branches in Git. If you want more details, we have a separate tutorial on the topic.Git is a popular version control system and an essential tool in a web developer's toolkit.īranches are a powerful and integral part of working with Git. 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 |