Skip to content
Browse files

Add Git Delete a Branch Locally and Remotely Guide

  • Loading branch information...
1 parent 84ea1f4 commit 5081eb8c0adeea24a765ed54c77f2915e1985661 @raisedadead raisedadead committed
Showing with 36 additions and 0 deletions.
  1. +36 −0 Git-Delete-a-Branch-both-locally-and-remotely.md
View
36 Git-Delete-a-Branch-both-locally-and-remotely.md
@@ -0,0 +1,36 @@
+#### When to Delete branches?
+
+Normally in a contribution flow `Branches` are a great way to work on different features, fixes, etc. while isolating them from the main codebase. So a repo may have a `master` branch, and separate branches to work on different features.
+
+Typically once the work is completed on a feature and it is recommended to delete the branch.
+
+#### The Delete workflow:
+
+Lets say you have a repo called as `AwesomeRepo`, and its hosted on Github, at a location such as `https://github.com/my_username/AwesomeRepo`.
+
+Also lets assume it has the branches like: <br>
+`master`<br>
+`feature/some-cool-new-stuff`<br>
+`fix/authentication`<br>
+`staging`<br>
+
+For consistency we will assume branch names are same on `local` as well as on the `remote`.
+
+Now, lets say you are done with that fix for authentication and want to remove the branch `fix/authentication`.
+
+#### Deleting the branch REMOTELY:
+
+Simply do:<br>
+`git push --delete <remote> <branch>`.
+
+For example: `git branch --delete origin fix/authentication`
+
+#### Deleting the branch LOCALLY:
+
+First checkout to a branch other that the one you want to delete:<br>
+`git checkout <branch>`. For example: `git checkout master`
+
+Git will not let you delete the branch you are currently on.
+
+Then proceed with deleting:
+`git branch -D <branch>`. For example: `git branch -D fix/authentication`

0 comments on commit 5081eb8

Please sign in to comment.
Something went wrong with that request. Please try again.