37

I have a visual studio solution with a few asp.net 5 project. Inside every project I have a wwwroot directory and inside this an app directory that contains the html views, .js and .map files that are typescript files compiled in this position.
With the standard configuration these files are included in the checkin. How can configure the .gitignore file so all the .js and .map files, inside every subdir of the wwwroot\app directory of every project in the solution are ignored?

1
  • 1
    If you have multiple projects and all projects need same set of git ignore rules, then you can use Global Git ignore rules concept to mention single gitignore file and use across all of your projects rather than creating individual gitgnore files. But this global git ignore file won't be a shared copy and your other teammates will not get benefited. Please refer Atlassian Git to check the steps.
    – sanit
    Commented Jan 4, 2018 at 5:20

2 Answers 2

46
wwwroot/app/**/*.js
wwwroot/app/**/*.map

The ** will match everything inside app, also multiple levels of subdirectories.

5
  • 16
    what happend if you have a js that is not a compiled file, for example a library? Commented Dec 21, 2016 at 19:31
  • 3
    @DiegoGonzález libs should go in a separate folder, not in /app (eg /lib, /node_modules etc)
    – Jay Wick
    Commented Mar 23, 2017 at 5:09
  • 3
    @Jay One problem with putting output into a separate folder is your code isn't running in the exact same context as the src so, for example, if you fs.readFile('./foo.md') then it'll fail -- unless you have a separate copy task to move all non js files into the /dist directory. IMO tsc should allow you to output with a custom file extention, e.g. .compiled.js which can then be explicitly ignored Commented Sep 13, 2018 at 12:04
  • 1
    *.js coverss *.js.map also Commented Apr 28, 2019 at 19:57
  • 2
    @Technotronic Wouldn't that be *.js.*?
    – Dai
    Commented Aug 18, 2020 at 8:44
22

Add the following lines to your .gitignore:

# Ignores compiled TypeScript files
**/wwwroot/app/**/*.map
**/wwwroot/app/**/*.js

You can read more about gitignore and supported patterns here.

** matches subdirectories recursively. The first one is there for the projects, the second one is there because you mentioned

inside every subdir of the wwwroot\app directory

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.