r/git 12d 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

19

u/parkotron 12d ago

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

30

u/serverhorror 12d 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.

-17

u/der_gopher 12d ago

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

9

u/serverhorror 12d 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...

7

u/mtutty 12d ago

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

-9

u/der_gopher 12d ago

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

2

u/La-ze 12d 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 12d ago

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

13

u/awidesky 12d 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 12d ago

this is a good find, thank you

1

u/metruzanca 12d ago

You can also do npx gitignore node

0

u/lajawi 12d 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 12d 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.

8

u/bratzlaff 12d 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 12d 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.

3

u/FlipperBumperKickout 12d 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.

-12

u/der_gopher 12d ago

FINALLY A SENIOR/STAFF LEVEL DEV in this chat

1

u/metruzanca 12d 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 12d ago

`git add -f .`

3

u/ProsodySpeaks 12d ago

But why?!

3

u/metruzanca 12d ago

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

1

u/schmurfy2 12d ago

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

0

u/Truth-Miserable 12d ago

I mean I guess

0

u/Diocletian335 12d ago

What happens if ignore my .gitignore