Git is a powerful version control system that allows you to easily develop software and maintain different branches for different streams of development. Sometimes you may need to delete both local and remote branches in git. This is a common requirement for developers who work with git. In this article, we will learn how to delete git branch locally & remotely.
How to Delete Git Branch Locally & Remotely
Here are the steps to delete git branch locally & remotely.
1. Delete Git Branch Locally
Here is the command to delete local branch form git repository. Replace <branch_name> with name of branch that you want to delete. The -d or –delete option will delete the branch if it has already merged in its upstream branch.
$ git branch -d <branch_name>
Alternatively, you can always use -D or –delete –force option to forcibly delete the branch irrespective of whether it is merged or not.
2. Delete Git Branch Remotely
Here is the command to delete remote branch.
$ git push -d <remote_name> <branch_name> OR $ git push <remote_name> --delete <branch_name>
In this article, we have learnt how to delete git branch locally. Git allows you to maintain multiple branches in your repository to work of different streams of development. If you don’t need a branch then you might want to delete it in order to save space. If a particular branch is not needed, then you may want to remove it from remote repository so that whoever clones it in future, does not have to download unnecessary branches to their local systems, thereby reducing the overall size of your repo.
How to Reset or Revert File to Specific Commit in Git
How to Find & Restore Deleted File in Git Repository
How to Set Vim Default Editor for Git
How to Use Variable as Key in JS Object
How to Format Number as Currency String