How can you change the default .gitignore Mix creates?

How can you change the default .gitignore Mix creates?

I need to add some stuff like vim’s .swp files and a whole load of others I haven’t which haven’t come to mind yet.

Thanks!

A .gitignore file is just a text-file which you can edit with a text editor.

It basically contains paths to all files or directories you want to ignore. These paths can contain wildcards, and they can be stacked. More information can be found in the git documentation.

I am creating lots of small projects in quick succession and it becomes annoying to edit the .gitgnore . I just want to know if the default file created by mix can be changed.

Ah! I see!

I jumped into the source code of Mix’s new task.

It seems like the gitignore text is hard-coded right now: It is written out on line 231, and then used on line 85 when generating a normal project, and on line 129 when generating an umbrella project.

If you want to alter what .gitignore file is used, I think the easiest option would be to alter/replace it after this task runs. Although I also find it highly likely that the team behind Mix is open to making the generated .gitignore file configurable.

1 Like

That is interesting. In fact the embed_text and the `embed_template1 commands seem to be the kind of thing I will need in some of my projects.

Are they specific to mix or are they general routines which are available in Elixir itself or are they specific to `mix’?

embed_text and embed_template are specific to Mix.

For your project, it might be worthwhile to create your own Mix Task. You can read more about this on its page in Mix’s documentation.

Multiple tutorials about this procedure also exist, such as:

2 Likes

You seem pretty quick at looking up source code in Mix.

Are you searching through the docs or do you have some kind of IDE tool which helps you navigate it quickly?

The reason it is so easy to find these things, is because Elixir and its tooling are very well documented. (And this is true for most third-party libraries on Hex.PM as well!)

I do not use any special tools, other than my favourite search engine, and ExDoc’s search function to find the function definitions or modules in the documntation I’m looking for. From there, it’s one click to go to the function’s source code on GitHub.

So it’s mostly because of the good documentation and easy-to-read sourcecode that it’s possible to find this stuff quickly. :smiley:

1 Like

Thanks for pointing it out. I have noticed that the </> link on the functions lead directyly to Github.

I take it the hexdocs are generated directly from Github?

In the case of third-party libraries, these are generated by running mix docs, which is automatically done when publishing your library using mix hex.publish. So they are generated locally.

It turns out that ExDoc allows you to specify the URL at which your source code is available. It will (I presume) assume that, from that URL, all relative paths to your source files work as intended. More info on ExDoc’s GitHub page.

1 Like

You don’t want to add your editors temporary files or any operating system related files into your projects git ignore. If anyone in you team does that you will end up with a git ignore even bigger then the remainder of your project.

Files that really pop up into the project tree because the build system does this belong into your projects ignore file.

Files that are created by your local tool set do belong into a user global ignore file. There is a good explanation of this available at gut hub. I can’t search for it right now since I’m only on a mobile phone…


addendum:

I was able to manage to get some “CPU”-time and was allowed to use my laptop even during vacancy :wink:

So I googled around and wasn’t able to find that github article I mentioned above, but the git manual is pretty clear on this as well:

Git - gitignore Documentation (emphasis mine):

Which file to place a pattern in depends on how the pattern is meant to be used.

  • Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that all developers will want to ignore) should go into a .gitignore file.

  • Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the $GIT_DIR/info/exclude file.

  • Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

8 Likes

I like to put “whatever my editor/IDE/… creates” not in project-specific git ignore files, but in ~/.gitignore-global and point git’s excludefile config at it. That way everybody can be happy - I put in .#* for Emacs, some collaborator *.swp for vim, etcetera, without cluttering project gitignores.

have you been able to gitignore the .elixir_ls folder and all subfolders and files inside it? I tried variations of excluding .elixir_ls (with and without trailing and starting slash) in a global and local config, but git still tracks it.

Files that you already added to the index will be considered by git until you remove them from the index. git rm them, then they won’t show up again if they are ignored properly.

If that doesn’t work, please show the corresponding parts of your git config and ignore files.

2 Likes

Here is the GitHub guide that @NobbZ was talking about.

https://help.github.com/articles/ignoring-files/

On the “Create a global .gitignore” section. There is even a link to a common ignore content to put in that file :wink:

2 Likes

I, sometimes tracked elixir ls folder, to get it away I used git rm --cached -fr .elixir_ls.
Note on --cached

3 Likes

yes, that was it. thank you!