Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

Git - xargs with git branch - fatal: branch name required

0 contributions
4 points

Problem:

When I execute command line:

git branch | grep -v "master" | xargs git branch -D

I get error:

fatal: branch name required

I'd like to execute another command after &&
but when I get this error it won't work

Solution:

Just add to xargs

--no-run-if-empty

// your command fixed

git branch | grep -v "master" | xargs --no-run-if-empty git branch -D

Explanation:
// when we don't have any local branches except master, run:

git branch | grep -v "master" | xargs git branch -D

// we will get error:

fatal: branch name required

// FIX - add '--no-run-if-empty' to xargs

git branch | grep -v "master" | xargs --no-run-if-empty git branch -D

// we will get no result

From xargs man:

-r, --no-run-if-empty
      If the standard input does not contain any nonblanks, do not
      run the command.  Normally, the command is run once even if
      there is no input.  This option is a GNU extension.

manuals:
http://man7.org/linux/man-pages/man1/xargs.1.html
https://git-scm.com/docs/git-branch

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more