AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Command line commands git delete branch12/30/2023 ![]() Suppose, we want to work on a file that is on a remote Github repository as another developer. By using the command ‘git push,’ the local repository’s files can be synced with the remote repository on Github. Suppose, we have made some changes in the file and want to push the changes to our remote repository on a particular branch. Learn more about DevOps in this DevOps Training in Sydney to get ahead in your career! Now, we are ready to operate the remote commands in our repository that we have just created. If you want more details, we have a separate tutorial on the topic.Step 3: Click on the Copy icon on the right side of the URL box of the Github repository to copy the link and paste it as shown below: git remote add origin “URL” 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
Read More
Leave a Reply. |