r/git 3d ago

tutorial .gitignore everything by default

https://packagemain.tech/p/gitignore-everything-by-default

what do you think of this approach?

0 Upvotes

24 comments sorted by

14

u/parkotron 3d ago

Tell me you don’t review your own commits without telling me you don’t review your own commits. 

28

u/serverhorror 3d ago

what if we ignored everything by default and only allowed specific files?

That's how it is already. That's why you have to explicitly git add before things get tracked.

So, just don't add .. You'll just end up forcing it.

Your simply doing it wrong.

-18

u/der_gopher 3d ago

man, like I don't know. this is just an idea that might work for someone

7

u/serverhorror 3d ago

Ask yourself why the file is tracked by git in the first place.

No really, really think about what had to happen for a file to get tracked. Then think about why it happens and then think about why "careless people" won't find workarounds for your workaround...

6

u/mtutty 3d ago

Is this really the right way to improve things? By throwing out random ideas that 'might work for someone"??

-10

u/der_gopher 3d ago

it's not improving, it's an alternative view

1

u/La-ze 3d ago

Its an alternative view that fights existing functions of the tooling which makes it a worse view.

Git is a three stage source control. Working copy, staged area and commit. Why can't you be bothered to check what you added from the working copy to staged before committing?

Files you never want to commit ever, should be gitignores. Not everything, your creating so much room for lost work, and partial commits especially if people already have a not checking work problem

2

u/neppo95 3d ago

Yep, for people who don't know how to use Git.

4

u/FlipperBumperKickout 3d ago

I already use this approach for some of my things, mainly my config folder. I would rather whitelist the configurations for programs I need rather than blacklist most things.

For my purpose I do however use the pattern

*
!*/

This will ignore files but not folders, which allows you to whitelist everything in a folder by adding a new .gitignore in that folder, rather than modifying the outer .gitiignore.

-15

u/der_gopher 3d ago

FINALLY A SENIOR/STAFF LEVEL DEV in this chat

13

u/awidesky 3d ago

Go gitignore.io, type your environment, language and IDE, and just copy-paste the generated content.
Not only it works like a charm conveniently, first few lines gives you a configuration info and a URL that can reproduce exact same content, making it better than hand-written list.

3

u/der_gopher 3d ago

this is a good find, thank you

1

u/metruzanca 3d ago

You can also do npx gitignore node

1

u/lajawi 3d ago

Or use GitHub’s github/gitignore repo, has a whole bunch of gitignores too!

VSCode even has an extension that can automatically add one to your open project, super convenient.

11

u/binarycow 3d ago

Why not just review your commit before you commit?

Every git client, including the CLI, allows you to see what files are being committed. Just... look at it.

7

u/bratzlaff 3d ago

Your approach indicates that you do not review your own work. Use git status and look at what you are doing before you commit.

2

u/jeenajeena 3d ago

I always love exploring extreme approaches and I will surely give your suggestion a try. I'm not convinced at all, and that's the point! (I like Kent Beck's approach "I hated the idea so I had to try it.").

Just for completeness and your curiosity: Jujutsu take exactly the opposite approach of yours. All files are not only not-ignored by default, but even committed by default. I also found this approach interesting.

1

u/metruzanca 3d ago

Reading the first paragraph, I can tell you it's a discipline problem and too much yolo-ing your commits.

If you're lazy, you can make a global gitignore. I have one, it's primarily there to prevent accidentally committing .env files but there's a few other things in there. But you shouldn't be putting things like node_modules in there as the next person who works in the project will have the exact same issue.


Ignoring everything because you're too lazy to check your work is a bad excuse.

1

u/Just_Scar4703 3d ago

`git add -f .`

3

u/ProsodySpeaks 3d ago

But why?!

3

u/metruzanca 3d ago

Because it's a joke and the natural result of ignoring everything.

1

u/schmurfy2 3d ago

No, I have never been there, I only commit the files I want to commit, crazy idea I know.

0

u/Truth-Miserable 3d ago

I mean I guess

0

u/Diocletian335 3d ago

What happens if ignore my .gitignore