-1

I'm working on several coding projects with git in collaboration (including my own). One problem I always have with git is that there are changes because of the use of a specific IDE or the use on different platforms.

Common problems:

  • Editor specific files are added for example in Vs, Vs Code, KDevelop, Kate etc. (sometimes also through extra plugins)
  • Platform settings change source code for example the end line sequence is different on Windows and Linux

I know there are some solutions for this for example using .gitignore for the first problem. But adding all these files for every single editor in gitignore is kinda annoying. And also not always possible (if it's not my own project).

Especially with my own collaboration project now, I realised that there have been so many problems due to the fact that I develop on Linux with atom, vs code, KDevelop and the other one on Windows with Vs. It takes ages to do all the configuration (.gitignore has now 350 lines of code after adding the vs template) and regarding the second problem, which line ending is used can differ from project to project ... so switching manually is annoying.

Is there any good solution, so new and existing contributors don't have to configure there editor for 3h and add bunch of extra files to .gitignore and switch always between different settings for different projects?

Leon0402
  • 160
  • 1
  • 9

3 Answers3

2

The options you have for ignoring files are

  • globally
  • publicly per-repo
  • privately per-repo

Global ignores (recommended for editors)

The value of core.excludesfile is a filename which contains .gitignore patterns: it will apply to all repos.

For example, my ~/.gitconfig sets this to ~/.gitignore_global, which contains (among other things)

# no backups
*.~
*.sw*

# no macOS pesky files
.DS_Store

# vim file browsing history
.netrwhist
# vim session files
Session.vim

# tags files
tag
tags

Publicly per-repo (least recommended)

Put your patterns in .gitignore (you can have one per directory in the repo).

This is great for ignoring build-specific or test-specific output, but general practice eschews user-specific things living here.

Privately per-repo

Edit $(git rev-parse --absolute-git-dir)/info/exclude (this is usually just .git/info/exclude, but for completeness, I won't assume so).

This is good for user-specific ignores that doesn't affect every repo. Because it's not automatically applied to every repo, and it can be hard to remember to set up if I make a new clone, I rarely use this option, but it is good to know about.

More information

D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
0

That's what the user- and repo-specific excludes (say git help ignore for the locations) are for: user-specific and this-repo-specific exclusions for detritus generated by tools you personally use, generally or just in a particular repo. There's no reason anyone should have to care what anybody else's tools use for temporary files, why would you track those?

Likewise for attributes, you can have personal and repo-specific attribute settings.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • 1
    As a tl;dr, add the editor stuff to a user wide gitignore (configurable via ~/.gitignore) or clone-specific .git/info/exclude – D. Ben Knoble Sep 10 '19 at 12:55
  • @D.BenKnoble You should write an answer instead, your comment was the most helpful regarding the editor specific files. With your tip I found the following link https://help.github.com/en/articles/ignoring-files, which explains it in detail. Thanks! – Leon0402 Sep 12 '19 at 12:39
0

Well, setting up a git repo and its ignored files may become a time consuming and complicated task. To help with this, github provides project templates that amongst other things, configure a .gitignore setup for your language of choice. You may have to mix a few of them.

But that may not be enough. I guess there may be pages explaining what to configure for each development environment (googling ignored files in dev environment X may help). But the rule of thumb is not to store under version control (almost all) the generated files and folders. For example, the .pdb files of MSVS, or the .cproject folder in eclipse. And of course the generated objects and libraries.

Another tricky issue is configuring the line ending. The fileformat must be agreed upon start (either DOS or linux). I specially recommend not to use the git option that allows mixing fileformats.

carnicer
  • 494
  • 3
  • 9