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
RBV Framework and closing of big brandsMiscellaneousWhat are Class Constants in PHP?PHPCheck if any column has NULL values in PostgresPostgresDebugging in WordPress Part 3: SCRIPT_DEBUG and SAVEQUERIESWordPressWill SQL (Relational) Database become obsolete?SQL/MySQLHow to Use Aggregate Functions (MIN, MAX, SUM, AVG, COUNT) to Summarize Data in SQL?SQL/MySQLHow to create two segues with two UIButtons on a single page (Swift 5.0)?SwiftA simple example on grid ‘auto-fill’ vs ‘auto-fit’CSSHow to create HTML elements with ID and class using JavaScript?HTMLIntroduction to Angular modules Part 2: NgModules and componentsAngularWhat is PostgreSQL? How similar or different it is from SQL?PostgresWhat is Etrieve Flow?Miscellaneous