I want to set up an alias in git for counting the total lines in a repository, so I went into Git Bash and entered this:
git config --global alias.linecount 'ls-files -z | xargs -0 wc -l'
After I entered the command, there was no error message. Then I entered
linecount
and got this error message:
sh: linecount: command not found
Is there a different way that I should be setting up an alias?
You're missing exclamation point (
!
).From:
man git-config
:You could do:
which would be an alias to
git
command, however since you're using shell syntax (like pipe), then all its parameters are interpreted bygit
it-self, so in this case you need to clarify that this should be treated as a shell command.Here is sample git alias in
~/.gitconfig
:From the command-line, the correct syntax would be:
Note: Adding
--global
is optional.Then you call it by:
You set up a git alias, not a shell alias.
You need to use git to run it.
You also need to use a shell-exec git alias if you expect to use shell features (like pipes).