$ git config --global core.excludesfile ~/.gitignore
Then you can put all the standard things you want to ignore into it: $ cat ~/.gitignore
.DS_Store
./drafts/
*.swp
And it will apply to all git commands on your computer. $ git config --global core.excludesfile ~/.gitignore
Then you can put all the standard things you want to ignore into it: $ cat ~/.gitignore
.DS_Store
./drafts/
*.swp
And it will apply to all git commands on your computer.We spent a good part of a day rebuilding a repo after a junior dev. left, when we found out they'd misused global gitignore and hadn't commited several important files due to an ignore they had set for a seperate project.
Lessons learnt. Ensure new devs don't use it, and code review on another machine than theirs...
A broken code should not be able to make it to production, there should be several steps to prevent that, including: Peer review, CI, QA, a staging environment, manual testing, etc.
Always assume that developers can screw up in trivial ways, and build your delivery system such that trivial screw ups will be caught early, rather then dictate how your devs setup their work stations.
Also don’t code review the code it self, review the diff.
A significant percentage of the most critical problems I detect during reviews is in the parts that have not been changed, invisible in the diff. A good diff is necessary, but not sufficient.
lmao!
Shocking I know /s.
But not everyone on here is part of a 20 man SV tech startup making the next social media for beagles and deploying 50 times a day...
Wrote more details about how I do this here: https://alexplescan.com/posts/2022/04/17/the-x-files/
I'd just been bumping into this problem, but hadn't conceptualized such an elegant solution, so kept fumbling around, adding/moving things, futzing around with git way more than I wanted to.
Thank you!
If another developer has added a 'source.file' and you pulled it in, your global gitignore would not be triggered, since the file is already tracked in the repo.
Tangentially, to prevent scenarios where generated code becomes out of sync, in your CI you should always re-run generators and check that `git status` shows no entries (and fail the build if it does).
I didn’t downvote you, and I don’t understand your sarcasm toward me when I’m trying to explain the practical answer to the question you asked. This isn’t just a few lines on a large project, and it’s not even about the extra lines at all. The issue is that personal preferences don’t belong in a shared file, and their presence can cause real and actual problems in a large project, problems I’ve witnessed and experienced first hand. One single bad line in .gitignore can cause trouble for everyone on the team when they need to checkout different branches. If you have 50 or 100 people adding their own ignores, they can and do easily conflict with each other. The shared .gitignore just isn’t the spot to list your personal folders, which is why git designed other places for you to put those.
* IDE/Editor (for example, add `.vscode` to your global gitignore if you use VSCode, add `.idea` if you use IntelliJ family, NOT add `.editorconfig` because that's intended to be cross environment)
* OS level spam (`.DS_Store`, etc.)
* Any file generated by a tool you use locally
Also a pro tip, I have this alias in my global git config:
why-ignore = check-ignore -v --no-index
So I can use `git why-ignore path/to/file` to show why a file is ignored (e.g. it shows which line in which gitignore file excluded it). .envrc # direnv, where I store my local project configuration
.vscode
and when I remember to use them: *.gitlocal
*.gitlocal*
To store files and directories I don't ever want to push, mostly for scratch files and logsAnyway, stuff in .gitignore can still be added to the index if you so wish.
Editors and IDEs are crafting tools. Crafting tools are meant to be mastered by workers (here: developers), not to enforce some team/company policy.
There are tools that already exists to enforce team policies like formatters, linters and so on. These tools generally integrate well with your editor of choice and can also be integrated on your CI pipelines.
What do you need to share btw? There's editorconfig, prettier, git hooks, etc. for style. direnv for configuration (I usually commit a .envrc.example file). I can't think of anything else.
For example specifying custom java faces components directory that will be used once the application is packaged into a war file, so IntelliJ knows they are accessible from JSP html files, and will autocomplete and show you what attributes you can modify on the component.
Another spot of problems was the plugin specific files (that inevitably also got checked in). When someone checked them in again and you hadn't updated this particular plugin, the newer file format caused it to crash. Not a problem for the dev who checked it in, but a problem for everyone else.
I am a strong proponent now of not checking in files that are IDE specific unless the developers are all completely aware of what files do what and the associated churn that a file may have through normal use.
Having maven and editorconfig instruct IntelliJ on how to make a workspace consistent results in less config file churn and avoids people accidentally checking in the compiler settings on their computer, database configurations (with passwords), run configurations (with passwords) and similar.
Checking in IDE files can be done, just that the developers all need to be diligent in checking what they check in. I've rarely been in an environment where that is the case for everyone.
I have a few team who does commit their .vscode folder, they use it to set up their environment the same way (usually when a project differs from another).
IntelliJ recommends not checking in a few types of files that are specific to the individual: https://intellij-support.jetbrains.com/hc/en-us/articles/206...
A .vscode/extensions.json file just specifies extension 'recommendations', and I find, really accelerates developers becoming productive in a project.
If I want to encourage small, one-off contributions, I want to support a user workflow that's as close as possible to:
git clone <project>
git switch -t <branch>
code <project>
npm ci | dotnet restore | terraform init | go get | <whatever>
<change and test>
git add <changes>
git commit
git push
With the right set of extension recommendations and default code settings, a VS code user can automatically be prompted to get the right test executors, linters, prettifiers, and so on so that they get instant feedback on their changes.It doesn't even matter if many users who work on the codebase day to day actually use emacs or a highly customized IntelliJ setup or whatever - the vscode settings specifically enable the driveby coder to get a working environment fast, and that helps enable the power users to not be bothered by feature requests that could be pull requests.
Also, the idea that there is some universal rule of 'what should be checked in to source control' that applies to EVERYTHING from personal projects to corporate internal monorepos to open source projects to undergrad joint coding projects to video games is... absurd.
If I can provide machine readable documentation on how to get your VSCode environment set up (in the form of a .vscode/extensions.json file), isn't that strictly better than merely human-readable documentation in README.md under a 'Recommended VSCode Extensions to work with this project' header?
But then again, language-specific settings will trump all other settings. And that’s one way to override workspace-level settings in your user settings if you want.
Here’s a detailed list of all levels of settings in VS Code, ordered by precedence: https://code.visualstudio.com/docs/getstarted/settings#_sett...
See also: https://code.visualstudio.com/docs/getstarted/settings#_sett...
At my last job we had a mono-repo with the .idea directory (for IntelliJ) commited. For Java projects IntelliJ needs to sometimes be directed to understand what folders are “resources” to allow better autocompletion and highlighting. For example specifying custom java faces components directory that will be used once the application is packaged into a war file, so IntelliJ knows they are accessible from JSP html files, and will autocomplete and show you what attributes you can modify on the component.
It’s definitely not a never situation. You can commit only certain files from the configuration (project settings not editor preferences)
I usually add something like specified in:
I add it to the repository settings, so all collogues have the same behavior.
Everyone aren't using all the freedesktop conventions, so no.
$ man git-config
It is however densely conditional wording -- could be simplified. *.sw?
Since I'm messy enough to sometimes end up with multiple of them for a few files. (Also, not messing with flash files in git, or in general...)But have since moved my vim swap files to ~/.vim/swap with `set directory=~/.vim/swap,.` in .vimrc.
~/.config/git/ignore
on Unixy platforms.So good.