Skip to main content

How to delete multiple Git branches using pattern Matching

https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Git-logo.svg/1280px-Git-logo.svg.png

To delete multiple branches using Git with pattern matching, you can use a combination of Git commands and shell scripting. Here's an example of how you can achieve this: 

1. Open a terminal or command prompt. 

2. Navigate to your Git repository directory. 

3. Use the following command to list all branches matching a specific pattern:

	
git branch | grep "<pattern>"

Replace <pattern> with the pattern you want to match. For example, if you want to delete all branches starting with "feature/", you can use feature/* as the pattern.

 This command lists all branches that match the specified pattern. 

4. Review the branch names listed and make sure they are the ones you want to delete. 

5. Once you're sure, you can use the following command to delete the branches:


git branch | grep "<pattern>" | xargs git branch -D
This command combines the previous `git branch` and `grep` commands to find the branches matching the pattern, and then uses `xargs` to pass the branch names to `git branch -D` for deletion. Note that the `-D` option is used instead of `-d` to force delete the branches, even if they have unmerged changes. Be cautious while using the force delete option. 

6. After executing the command, Git will delete the branches matching the pattern. Remember to exercise caution when deleting branches, as the process cannot be undone. Always double-check the branch names before proceeding.

 

Comments

Popular Posts

List of latest and most asked PHP practical interviews questions & answers

Core PHP Practical Interview Questions In this blog post I am sharing a list of some most asked PHP interview questions & answers. These are very useful and helpful for the freshers and experienced developer too. I have taken these questions from different sources and listed here at one place. Ques. How to reverse a string without using any builtin function? Ans: <?php $str = 'My name is Diwakar Kumar'; $len = 0; while(isset($str[$len]) != '') $len++; for($i = $len ; $i >= 0 ; $i--) { echo @$str[$i]; } Ques: Write a function to check if a given string is a palindrome or not. Ans: 1st Method: <?php function isPalindrome($str) { $str = strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $str)); // Convert to lowercase and remove non-alphanumeric characters $reverse = strrev($str); // Reverse the string return $str === $reverse; // Compare original and reversed string } 2nd Method: <?php funct

Bootstrap Responsive Media Queries CSS Tips

AS a developer I faces lots of problem while making website responsive to make website visible correctly on all devices like mobile, tablet and desktop. So, today I am sharing some Bootstrap responsive CSS styles and Media Queries  tips with you. But make sure that you are not repeating the same media queries for the same screen size. Otherwise it will override your previous CSS style rules.    The Grid Sizes .col-xs-$ => Extra Small (Phones Less than 768px) .col-sm-$ => Small Devices (Tablets 768px and Up) .col-md-$ => Medium Devices (Desktops 992px and Up) .col-lg-$  => Large Devices (Large Desktops 1200px and Up) Here is the Responsive CSS Style for all Screen Sizes Read more: https://scotch.io/tutorials/default-sizes-for-twitter-bootstraps-media-queries

How to take user input from terminal(stdin) in Rust?

In Rust, you can use the std::io module from the standard library to read input from the user. Here's an example that demonstrates how to get input from the user: use std::io; fn main() { // Create a new instance of `std::io::stdin` for reading user input let mut input = String::new(); // Prompt the user for input println!("Enter your name:"); // Read input from the user io::stdin() .read_line(&mut input) .expect("Failed to read line"); // Trim any trailing whitespace or newlines from the input let name = input.trim(); // Display the user's input println!("Hello, {}!", name); } In this example, we create a mutable String variable named input to store the user's input. We then use the std::io::stdin() function to obtain a handle to the standard input stream. Next, we call the read_line() method on the input stream, passing a mutable reference to the input variable. The r