Yogesh Chauhan's Blog

How to delete a local and a remote Git branches?

in Miscellaneous on December 21, 2021

Delete Local Branch

This is how you can delete a local branch:

git branch (-d | -D) [-r] 

branchname will be deleted if you use a -d or -D option.

You can delete one or more than branch using the command above.

Note that if a branch has a reflog then that will also be deleted.

You can use -r and -d together to delete remote-tracking branches.


Delete one branch

This command will delete one branch named “test” with force.

git branch -D test

Delete multiple remote branches

Make sure to configure the fetch or pull otherwise they will create the branches again.

git branch -d -r origin/abc origin/xy origin/zzz

Command Options

-d is the shortcut for –delete

-D is the shortcut for –delete –force

-r is the shortcut for –remotes

Read more about it on Git-Scm

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Where is the PHP log file located on Mac OS?PHPComponents and Props in ReactReactWhat’s a Closure in JavaScript?JavaScriptAccessing and Setting features of JavaScript ObjectsJavaScriptHow does AdSense calculate page loading time?JavaScriptHow to Commit and Rollback Changes in SQL?SQL/MySQLHow to implement NSNumberFormatter in Swift for currency?SwiftCSS Attribute SelectorsCSS3 Types of Arrays in PHPPHPLearn to create your skill bar using CSSCSSadd_filter function in WordPressWordPressHow to draw an SVG path on scroll using JavaScript?JavaScript