0

After working for a few weeks, I always accumulate a lot of branches, frequently called feature/* or daniel/*.

From time to time, I delete all my local branches running this command (windows):

git branch -d (git branch --list 'feature/*').trim()

After frequently forgetting this command, I'd like to create an alias for it (with a string argument) ideally like this:

git del 'feature/*'

How can I create this alias?


I was trying this:

[alias]

    del = '!set -eu; git branch -d (git branch --list "$1").trim()'

but it doesn't work and I ran out of ideas.

1
  • 1
    In my opinion this question answers the question for Bash at least. The only difference is that you ask for Git alias. Commented Sep 11, 2024 at 7:37

1 Answer 1

1

Instead of nesting commands, you could pipe them and retrieve the result of your git branch --list $1 to feed git branch -d with xargs -r.

To expand an alias with parameterized commands piped together, you could use the sh command and supply it with a string containing the command list.

Your alias could look like this

git config --local alias.del '!sh -c "set -eu | git branch --list $1 | xargs -r git branch -d"'

and be used in the following way

# deleting all branches starting with feature/
git del feature/*

# deleting all branches starting with daniele/
git del daniel/*
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.