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 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #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
Is PHP still good for back-end programming?PHPapply_filters function in WordPressWordPressHow to apply style only to first child and/or only to children other than the first child?CSSIntroduction to components and templates Part 4: Pipes and DirectivesAngularComposing and Extracting Components in ReactReactperspective property in CSSCSSHow to set the permissions on all files and folders in Mac?MiscellaneousCONCAT and CONCAT_WS Functions in PostgresPostgresHow to Sort (Shuffle) an Array in Random Order in JavaScript?JavaScriptHow to Install PHP composer in Mac OS Catalina?PHPHow to Use SQL MAX() Function with Dates?SQL/MySQLWhat is Prototypal Inheritance in JavaScript?JavaScript