Deleting a Git branch locally and remotely

 It is simple to delete a Git branch. We can delete a Git branch locally and remotely with simple git commands. 

It is common to have different branches. There is a great way to work on different features and fixes. Repos often have a master branch for the main codebase and developers create other branches to work on different features. Once work is completed on a feature, it is often recommended to delete the branch.


Deleting a branch Locally:

git branch -d <branch>

e.g.   git branch -d task/story_1

The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. 


Deleting a branch Remotely:

git push <remote> --delete <branch>

e.g.   git push origin --delete task/story_1

The branch is now deleted remotely



Post a Comment

If you have any questions or concerns, please let me know.

Previous Post Next Post