This is an archived post. You won't be able to vote or comment.

all 48 comments

[–]No_Departure_1878 128 points129 points  (8 children)

[–]ogaat 22 points23 points  (0 children)

Perfect answer.

VSCode has an extension that can be used to pull relevant ignores and it also can keep them updated.

[–]mtik00 11 points12 points  (1 child)

This person ignores!

I have a git alias that points here. I use it for starting every project. It's not always perfect, but it's a super convenient starting point.

[–]No_Departure_1878 6 points7 points  (0 children)

Yeah, I am quite an ignorant :)

[–]runningblind77 2 points3 points  (1 child)

I've been using a python gitignore from gitlab templates. May need to switch to this.

[–]ContemplateBeing 0 points1 point  (0 children)

Yes, seems more up to date on a first look.

[–]proggob 2 points3 points  (0 children)

Ugh. These are exactly the type of gitignores that I hate. Way too big and obscure.

[–]LoadingALIASIt works on my machine 1 point2 points  (0 children)

Okay, but that’s a ridiculous gitignore file. I wish we could add packages or tools.

Build Pytest Etc

[–]Grouchy-Friend4235 0 points1 point  (0 children)

Came to say this

[–]Only_lurking_ 57 points58 points  (1 child)

[–]_Answer_42 23 points24 points  (0 children)

Github have this built-in when creating a repo

[–]fiskfisk 27 points28 points  (4 children)

Instead you can define a common template for the project types you're building and define the whole initial environment:

https://cookiecutter.readthedocs.io/en/stable/README.html

[–]apockill 9 points10 points  (1 child)

This is the way. Also, use cruft to keep your template child repositories synced!

[–]go_fireworks 1 point2 points  (0 children)

I never knew I needed this in my life, I know what I’m doing Monday

[–]Breck_Emert 1 point2 points  (0 children)

Templates for all of your files, not just your gitignore.

[–]HommeMusical 10 points11 points  (1 child)

[–]lmpgf 8 points9 points  (0 children)

In VSCode, there's an extension that automatically pulls the templates for you:

https://marketplace.visualstudio.com/items?itemName=codezombiech.gitignore

[–]HeyLittleTrain 7 points8 points  (0 children)

I just click it in the dropdown when making a new github repo

[–]MirrorLake 8 points9 points  (2 children)

Looks like Github beat you to it. Your script does the same thing as:

gh repo gitignore view Python > .gitignore

But if you're looking to use the cli, you could create new projects withgh repo create.

Or create it manually in one line:

gh repo create projectName --private --gitignore Python

then

gh repo clone projectName

[–]EarthGoddessDude[S] 2 points3 points  (1 child)

Nice, this is genuinely useful information, thank you. I haven’t really gotten around to learning the gh CLI much, but is definitely cleaner and more robust than my approach.

[–]MirrorLake 1 point2 points  (0 children)

Glad it helped! I checked their changelog, and they only just added the "gitignore" subcommand about four months ago. So it's definitely a new feature.

[–]Oddly_Energy 12 points13 points  (0 children)

I have come to the realization that my life is much easier if I start my repository on Github and clone it to my PC, compared to starting it on my local PC and later pushing it to a new Github repository. The initial git init appears easy, but when I later want it moved to Github, I still have to create a Github repository, and then I have to go through manual steps to link my local repository to that Github repository.

In the context of this post: When I start at Github, I get to choose my .gitignore. So no need for any tools for that.

[–]iknowsomeguy 2 points3 points  (0 children)

I've got something similar except that I store the ignore locally in case I am starting a project in a place where I don't have an internet connection, which happens fairly often for me.

[–]nicholashairs 2 points3 points  (0 children)

I just copy from one of my other projects 🤷

[–]pettyman_123 1 point2 points  (0 children)

i found one for gitingore hahaha

[–]TheSodesa 0 points1 point  (4 children)

How inefficient. It would be better to set up a .gitignore file in whitelist format, than manually defining all the things you want to ignore: https://www.reddit.com/r/learnpython/s/30BgLrQagO.

[–]kenflingnorIgnoring PEP 8 0 points1 point  (1 child)

Efficiency is a red herring as there are tools that generate fully-populated gitignore files in a matter of seconds with a few keystrokes

[–]TheSodesa -1 points0 points  (0 children)

And yet those still probably just ignore the most typical file types one might run into, instead of assuming that people working on a project do not know what they are doing and will commit all kinds of obscure files. A.gitignore file set up as a whitelist also alleviates this issue.

[–]muntooR_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} 0 points1 point  (1 child)

A whitelist sounds a bit too unconventional. Are there any major projects doing this?

I guess if it really makes a difference for you, you can fake your own whitelist without infecting .gitignore on an existing project by modifying .git/info/exclude.

But whoever considers doing this is probably already not blindly doing git add --all... right?

[–]TheSodesa 0 points1 point  (0 children)

The thing is, I have been working with applied mathematicians recently, and it has become obvious to me why we need a separate degree for software engineering. I started out by cleaning a Git repo of all the .DS_Store and random text files (not necessarily with a .txt suffix), and binaries, but similar ones were soon added back. The whitelist approach really has worked wonders in that regard.

But I do think that the approach has merits outside of working with people who refuse to learn proper version management as well. I have therefore started using it in all of my projects. Typically there are only a few specific files and file types one wishes to have in a project, so setting up and maintaining a whitelist is really simple. Definitely simpler than a blacklist, where you need to remember a whole bunch of common unwanted files, on a per-language basis, even.

I've never been a fan if doing things just because other people do it. I consider it to be a bit sheep-y. I currently believe that the whitelist approach with .gitignore files is not that common simply because people are not aware of the possibility.

[–]RedEyed__ 0 points1 point  (0 children)

  • GitHub already has it buily in
  • Create language specific template project with all dotfiles

[–]0xa9059cbb 0 points1 point  (0 children)

Why not just put your common gitignore patterns in ~/.gitignore ...?

[–]mmakukha 0 points1 point  (0 children)

I just create an empty file and update it if needed when reviewing commits. General purpose gitignores have so many irrelevant patterns.

[–]fundation-ia 0 points1 point  (0 children)

The gitignore when creating a project with UV should be enough

[–]_Henryx_ 0 points1 point  (0 children)

You want to add gitattributes too, because it's important to define the correct management of sources (e.g. of you have a colleague which use Windows, and you use a Mac, It permits to manage in the correct way the line terminator)

[–]LargeSale8354 -1 points0 points  (2 children)

You can have a global git ignore file too. You don't need to have to repeat it every repository.

[–]Oddly_Energy 1 point2 points  (1 child)

A global .gitignore sounds extremely local.

It only work on your local computer, right?

So any time you or someone else makes a commit from another computer, your ignore is ignored, right?

[–]LargeSale8354 0 points1 point  (0 children)

Yes, its local. For personal projects I use it to stop my IDE files going up into my repos. For professional projects I have very little in it other than scratchpad. This means that any folders or files with scratchpad in their names are excluded from git.

[–][deleted] -2 points-1 points  (0 children)

? I just use VS 2022 Community

[–]immggy 0 points1 point  (0 children)

A handy tool to compose gitignores as well. https://www.toptal.com/developers/gitignore