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 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

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
Dynamically generate names in SCSS (animation example)SCSSHow to create bouncing balls using HTML canvas and JavaScript?HTMLWhat are Controlled Components in React?ReactHow to create a Star Ratings using CSS?CSSHow to hide and show menu on scroll using JavaScript and CSS?CSSHow to float an image around texts?CSSWordPress 5.7 is migrating to latest jQuery version and people are freaking outjQueryWordPress: How to access first and random row values from a repeater field in ACF?WordPressAdd animation to your skills bar using CSSCSSNATURAL JOIN in PostgresPostgres@forward modules with a prefix in SCSS (Sass)SCSSPHP Login System using PDO Part 1: Create User Registration PagePHP