EN
Git - xargs with git branch - fatal: branch name required
4 points
When I execute command line:
xxxxxxxxxx
1
git branch | grep -v "master" | xargs git branch -D
I get error:
xxxxxxxxxx
1
fatal: branch name required
I'd like to execute another command after &&
but when I get this error it won't work
Just add to xargs
xxxxxxxxxx
1
--no-run-if-empty
// your command fixed
xxxxxxxxxx
1
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:
xxxxxxxxxx
1
git branch | grep -v "master" | xargs git branch -D
// we will get error:
xxxxxxxxxx
1
fatal: branch name required
// FIX - add '--no-run-if-empty' to xargs
xxxxxxxxxx
1
git branch | grep -v "master" | xargs --no-run-if-empty git branch -D
// we will get no result
From xargs man:
xxxxxxxxxx
1
-r, --no-run-if-empty
2
If the standard input does not contain any nonblanks, do not
3
run the command. Normally, the command is run once even if
4
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