Question

On Windows, I'm trying to create an alias for Git Add to automatically select only C# related files.

My current alias is:

acs = add *.cs *.csproj *.sln

I keep getting this error: fatal: pathspec '*.sln' did not match any files, which is expected, since the specific folder I am in contains only the project and not the solution. (i.e. *.cs and *.csproj both exist)

I want to create an alias that would work for all C# folders.


Say I have 2 folders.

Folder1 contains:

  • 1.foo
  • 2.foo

Folder2 contains:

  • 1.foo
  • 2.bar

In Git Add, is it possible to create a line that would work for both folders, regardless of the presence of the files mentionned in the wildcards ?

I would have expected (hoped for) something like:

git add *.foo|*.bar

Is there any OR wildcard ?

Was it helpful?

Solution

I don't see any way to make git add's convenience globbing ignore a pattern that doesn't match anything, but there are much more powerful ways to build command lines.

First, a handy alias:

git config --global alias.files 'ls-files -oc --exclude-standard'

then

git config alias.acs '!git files -z *.cs *.csproj *.sln | xargs --null git add --'

gets you what you want.

OTHER TIPS

try this:

acs = add --ignore-errors *.cs *.csproj *.sln
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top