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 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#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 #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS?
You might also like these
Solution for “Yarn build: Failed because of a stylelint error”WordPressHow different is Handling Events in React vs HTML DOM?ReactCreate a simple bar chart and column chart using pure CSS gridCSSHow to convert an HTML radio buttons into a toggle switch using CSS?CSSThe difference between Class declarations and Class expressions in JavaScriptJavaScriptIs there a difference between SCSS and Sass?SCSSINTERSECT and EXCEPT in PostgresPostgresWhat is Etrieve Flow?MiscellaneousRecursive WITH Queries in Postgres (Common Table Expressions)PostgresIf statement shorthand examples in JavaScriptJavaScriptList of social media icon logo color codes in HEXMiscellaneousHow to set the permissions on all files and folders in Mac?Miscellaneous