Git ignore generated extensions

I’d like to keep JavaScript (.js) files under git control.

However, if a TypeScript (.ts) file exists, I’d like to ignore the associated .js file.

  • The concept of snapshot
  • How to identify conflicting commits by hash during git rebase?
  • Is it possible to see a remote's remotes in git?
  • go back to a specific commit then go back to the present
  • Is it possible to store only a checksum of a large file in git?
  • GitHub - HTTPS access
  • Is there a way to achieve this with git?

    EDIT: Preferably without changing directories and refactoring all the existing code.

  • Git pull reverted commits in master?
  • git replacing LF with CRLF
  • git autocrlf input does convert line-endings but from LF to CRLF?
  • Git, how to set .gitattributes for Storyboards and .xib files
  • Does git rebase create more conflicts than git merge?
  • Using git with a project in a Dropbox folder
  • One Solution collect form web for “Git ignore generated extensions”

    A typical way to do this is to put any compiled output in some distribution directory. You might organized your directory structure like so:

      ... various JavaScript files, etc.
      ... compiled output from any build tool you're using

    Then in git, you can just ignore the dist directory, and assume that anyone who is going to pull down that repo and work on it will either run the build tool manually, or it will built automatically as part of the installation process.

    In other words, it’s easier to organize it without depending on a specific set of git functionality. This is a pretty common pattern in the JavaScript world.

    If you don’t go for that method, another way to do it is to add some identifier to the files that you want to ignore. For example, you might prepend all your files you want to ignore with _ and then add this rule to your .gitignore (see this answer for why the following works):


    There are some drawbacks to this second approach:

    1. Other libraries you use may use filenames that start with a similar identifier and there will be collisions
    2. It’s hard to maintain; you may want to change the identifier later if there is some collision or you change your mind about your structure, and you’ll have to go back through all the files and change the names (of course, this can be automated, but it might be a pain)

    Hope that helps.

    Git Baby is a git and github fan, let's start git clone.