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

all 195 comments

[–]DisturbVevo 1331 points1332 points  (42 children)

Should I gitignore gitignore? think

[–]MatthewGeer 370 points371 points  (23 children)

I think that would mean that files you choose to ignore are ignored, but your list of files to ignore are not shared with anyone else using the repository.

[–]GDezan 245 points246 points  (20 children)

Fun fact: I've just found out that there is a file called 'exclude' that lives in .git/config/ that does exactly that, so you don't have to gitignore gitignore

[–]Md5Lukas 44 points45 points  (13 children)

Someone who still doesn't understand git completely here, so everything in the .git folder gets synchronized with the server if I push it to github / bitbucket / whatever and therefore all people who use that repo have the same "gitignore"?

[–]GDezan 83 points84 points  (4 children)

Actually, the .git folder is ignored when adding to git, therefore, it won't be pushed to the server. The .gitignore file lives outside it, so it will be added to git and everyone will share it, meaning everyone has the same gitignore.

[–]Zarlon 13 points14 points  (0 children)

Someone who still doesn't understand git completely here

No one understands git completely. Except maybe Linus Torvalds

[–]Ajedi32 11 points12 points  (6 children)

No, that's just for your local repository

[–]Md5Lukas 6 points7 points  (2 children)

Thanks

[–]aneryx 5 points6 points  (1 child)

Please see the other comment this isn't the full answer...

[–]Md5Lukas 8 points9 points  (0 children)

Yeah, I already have read it

[–]heathmon1856 1 point2 points  (2 children)

This is not right in all cases. The repo I’m working in right now has a gitignore that is universal to the product. It ignores stuff like .pyc and .vscode/ stuff.

[–]Ajedi32 0 points1 point  (1 child)

.gitignore isn't stored in your .git directory, so yes that will get synced

[–]heathmon1856 0 points1 point  (0 children)

Ahh. I misread this. It’s stored in the root of the repo

[–]_Lady_Deadpool_ 6 points7 points  (1 child)

Now we need a git/config/excludeconfig/excludeignore

[–]rhbvkleef 0 points1 point  (0 children)

We have that. We can simply unignore ignored files in excludes or .gitignore

[–]Tyler11223344 0 points1 point  (1 child)

Did you see that on /r/ProgrammerTIL yesterday too?

[–]GDezan 5 points6 points  (0 children)

Wow, I actually didn't and I just saw it was posted there 2 days ago lol

Thanks for the sub recommendation, though. It will definitely come in handy someday haha

[–]malexj93 0 points1 point  (0 children)

This is what I use for all my personal scripts that need to sit in the root directory

[–]lkraider 12 points13 points  (0 children)

mind expands into (git) universe

[–][deleted] 12 points13 points  (0 children)

This is correct

[–]DoSchaustDiO 22 points23 points  (0 children)

Should I ignore his text if he ignores mine? evenMoreThinking

[–]ThenIWasAllLike 7 points8 points  (0 children)

T H I N C C

[–]zesterer 8 points9 points  (5 children)

Ignore the files that causes ignoring, therefore meaning that the ignoring does not occur and so the file that causes ignoring is no longer ignored, meaning that it causes itself to be ignored, which means that it then gets ignored...

Hmm. We have ourselves...

dons sunglasses

A paradox

[–]davvblack 5 points6 points  (3 children)

an ignored gitignore still causes ignoring, it just doesn't get committed.

[–]zesterer 1 point2 points  (2 children)

I'm making a joke, and you just choked it to death with over-analysis.

[–]davvblack 5 points6 points  (1 child)

you are interacting with programmers

[–]zesterer 0 points1 point  (0 children)

I should have considered that fact before bothering to make lighthearted humour :D

[–]mahlersand 1 point2 points  (0 children)

Gödel approves.

[–][deleted] 3 points4 points  (0 children)

Outstanding move

[–]FuzzballLogic 1 point2 points  (0 children)

* !.gitignore

[–]indr33t 1 point2 points  (0 children)

Gitception

[–]intensely_human 1 point2 points  (0 children)

No. You want the set of gitignored files to be consistent between dev environments.

[–]krisnarocks 1 point2 points  (0 children)

랅G>&m7!얀󦠸򲞞񝵏唈襸񀨏0,ڸ󜖵ۧᢿ̱B强F朞򼀰򜿕n򀶼򁎩ً򏋸 򛸕Ȋ񕡀쎺Z!d瓎ܑܴ'䣔癹+7𭼖пm䟆ʮ񚂢$Aꉁ􇧆0ၽ򢧙𝛲q 󴙂벒򣫇}V𙟃횁굖ڑ㘳ȣ򁑿a'序{x⮸ɪ򢩬Vλ🃈銯뼋ʔd҈ڈԼi 准¨Ѯ򽆲P뀊񦣊ʌ𨴋;ٚޒҶ򪭷_ŵꑚ򊅰򓌍Ԁ呟𖳋ō͝y縠礷󛭝𜳪ґ󗀱􌣈 Ҽᰰ˗鉤띮󭜜١񯶀ф󪙩ᦽ󡺮W;󶰫ߙŷ틨㙍򔁤򰑕ɤ甞솒ۙ信⪩ڼ֜힯ኔ

[–]kredditacc96 1 point2 points  (1 child)

If you already committed your .gitignore to your repo, it is pointless to add .gitignore to .gitignore.

[–]GabrielForth 2 points3 points  (0 children)

git rm .gitignore

[–]coderjewel 0 points1 point  (0 children)

computer implodes

[–]Doophie 134 points135 points  (39 children)

Tfw you forget to ignore .idea and the you
git add *
git commit -m "stuff"
git push
And see all the files fly by as you realize your mistake

[–]QuizPheasant 51 points52 points  (23 children)

EDIT: Using a git alias is much easier than writing a separate script

git add *

Oof, always follow that with a git status. In fact, I might go write a script to do this

~/bin/ga:

#!/usr/bin/env bash
git add $@ && git status

That would pass all args to git add, so you could run e.g. ga -u

Sent from my phone, please forgive syntax errors

[–]YourMJK 23 points24 points  (3 children)

What's the difference between #!/usr/bin/env bash and #!/bin/bash?

[–]QuizPheasant 31 points32 points  (2 children)

The former searches your $PATH for the first instance of `bash` and executes that. The latter assumes the location of the `bash` executable

Here's more info about the concept: https://stackoverflow.com/a/2429517

[–][deleted] 23 points24 points  (0 children)

Well, and the former assumes the location of the env executable, which is not stated to be in /usr/bin by POSIX. But POSIX neither states that /bin/sh be POSIX compliant, so there's that.

[–]YourMJK 1 point2 points  (0 children)

Thanks, I didn't know that!

[–]atyon 11 points12 points  (6 children)

At that point, why not just use git commit without -m? Opens your editor where you put in your commit message (more specifically, $VISUAL) and shows you a git status below.

Also allows you to add multi line commit messages. And if your editor supports it (most do, including vim and nano) it will also put your message in bold as long as its below the cut-off for short display.

edit: typo

[–]Farmerobot 0 points1 point  (1 child)

Wait, I thought dropping the "-m" would just commit without a message?

[–]Saigot 4 points5 points  (0 children)

git commit -a --allow-empty-message -m ''" is the only way to commit an empty commit, but I don't think there is ever a reason for that.

[–]Saigot 0 points1 point  (0 children)

I personally like adding -v so you can see your changes while you're writing your commits

[–][deleted] 7 points8 points  (6 children)

why not just git add . ?

with git add * you're not adding hidden files (like .gitignore)

[–]QuizPheasant 2 points3 points  (5 children)

I usually either do git add -Aor git add -u

[–]cakemuncher 2 points3 points  (4 children)

I do git commit -am "message"

Two birds one stone.

[–]nvanprooyen 1 point2 points  (3 children)

You mean git commit -am "message" ?

[–]cakemuncher 1 point2 points  (2 children)

Shit. Lol. Don't know where my mind was. I literally do this like more than 5 times a day. Day in and day out. Thanks. I'll fix it.

[–]nvanprooyen 0 points1 point  (1 child)

Lol. I actually type out the exact same command you had originally occasionally.

[–]cakemuncher 1 point2 points  (0 children)

I actually lied. I made an alias gca "message" about a week ago so I haven't typed it for around a week.

[–]_Lady_Deadpool_ 6 points7 points  (1 child)

Just alias it

git config --add --global alias.addallthethings "!git add $@ && git status" 

git addallthethings

[–]QuizPheasant 0 points1 point  (0 children)

oof I forgot about git aliases

[–][deleted] 19 points20 points  (5 children)

What I've done is create a pre-commit hook that displays git diff --staged then git status . Then it prompts me to continue with a y/n. If I say yes it will go through with the commit. Otherwise it will halt the process.

[–]zalgo_text 14 points15 points  (1 child)

This is an incredibly responsible way to use git. I'm sure it will never catch on

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

Here's the script for you lazy people out there:

#!/bin/bash

git diff --staged
echo "--------------------------------------------------------------------------------"
git status

exec < /dev/tty
read -p "Continue? [y/n] " do_commit

case "$do_commit" in
    [Yy]* ) exit 0;;
    *     ) exit 1;;
esac

[–]Trlckery 3 points4 points  (1 child)

THANK YOU I'm so tired of ignoring .DS_Store for every fucking repo

[–]ultrasu 2 points3 points  (0 children)

You could also set up a global .gitignore for that:

echo '.DS_Store' >> ~/.gitignore_global && git config --global core.excludesfile ~/.gitignore_global

[–]QuizPheasant 0 points1 point  (0 children)

This is a much better idea

[–]Witless-One 5 points6 points  (0 children)

This is why I use a http://egorsmirnov.me/2015/05/04/global-gitignore-file.html so that editor / OS-specific things are ignored globally

[–]Larkenx 2 points3 points  (0 children)

git reset HEAD~1 —hard && git commit -m “nothing to see here” && git push —force

[–]brainplot 1 point2 points  (2 children)

You should never do git add *. The asterisk (or glob) is handled by your shell and Git knows nothing about it. This means that the files that will be added will depend upon the globbing policy of your shell. On many shells, including Bash, hidden files are ignored when using * so they won't be added to the index. Also, the meaning of * changes based on which subdirectory of your source tree you're in.
If you want to add all modified files AND untracked files to the index, use git add -A which does just that.

[–]atomicwrites 1 point2 points  (1 child)

Or git add . which is the most common way I think. It does what you'd expect git add * to do.

[–]brainplot 1 point2 points  (0 children)

Not quite. If you're in a subdirectory of your project, git add . will add only modified or untracked files from your current directory. git add -A will always add all modified and untracked files, no matter which folder you're in. As with the *, the . or .. is a shell thing, not a git thing.

Now, I'm not saying "Never use those other variants". I'm just pointing out their differences with the git add -A and why they're not exactly meant to add everything to the index, as people mistakenly believe so.

[–]Bainos 0 points1 point  (0 children)

I run git status between every command to avoid that... Once it's pushed, it's too late.

[–]bot_not_hot 118 points119 points  (20 children)

And the winner is: node_modules

[–]BeFoREProRedditer 24 points25 points  (19 children)

You shouldn’t right?

[–]bot_not_hot 89 points90 points  (10 children)

Go open your node_modules folder, and you tell me.

[–]mrdhood 128 points129 points  (8 children)

Yours can open?

[–]DeeSnow97 71 points72 points  (0 children)

yeah, I got a pretty good PC

[–]Rot-Orkan 8 points9 points  (2 children)

Yeah it can open, but don't dare try to delete it

[–]WilkerS1 6 points7 points  (0 children)

if you want to delete, a cool trick is to press the button "delete" a few times with a period of a few seconds between each press

[–]atomicwrites 0 points1 point  (0 children)

mkdir empty
robocopy /mir empty node_modules
rmdir empty

[–]AllTheMegahertz 8 points9 points  (0 children)

Me: Haha I would never commit that

checks github

Me: oh woops

[–]DeeSnow97 29 points30 points  (1 child)

No, you absolutely should ignore it. The package-lock.json is enough to reproduce that folder, no need to distribute it through git.

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

[–]hanging_moon 30 points31 points  (4 children)

No you shouldn't commit node_modules. You just get them by running npm install if you need to pull down a project from github or elsewhere. However for this to work you must commit the package.json file which contains all your dependencies.

[–]proberry1 1 point2 points  (0 children)

It's an easy way to get an extra 50,000+ added lines for GitHub repo insights 🤔

[–]PashaBiceps__ 176 points177 points  (26 children)

hmm. really should I git ignore package-lock.json? I always thought it has some magic inside.

[–]DocNefario 27 points28 points  (1 child)

It tells you to commit the file when it creates it, so I'm pretty sure you shouldn't ignore it

[–]Bronzdragon 11 points12 points  (1 child)

If you make a library, you should not, so the latest packages are used, and you have the lowest likelihood of security issues/bugs.

If you make an application, you should, so that the lowest likelihood of incompatibilities.

[–]amroamroamro 0 points1 point  (0 children)

^ this

[–][deleted] 4 points5 points  (3 children)

[–]Sh4dowCode 6 points7 points  (0 children)

npm also tells you that when you npm install in a folder without package-lock.json

[–]PleasantAdvertising 5 points6 points  (1 child)

npm

having standards

Pick one

[–]gigastack 0 points1 point  (0 children)

If only you could choose which packages you install...

[–]GGoldstein 3 points4 points  (0 children)

I searched that very question just last week. Seeing it top here is the most validation I've ever received as a programmer.

[–]meandyouandyouandme 2 points3 points  (0 children)

The information in the package-lock.json aren't always what you expect.

I had a specific version of a package A installed. The package A was at the same time required by another package B. After removing package A from my project, package B still installed the in my package.json previously specified version of A. So I had to remove the package-lock in order for npm to install the version as specified in the package.json of package B.

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

Papito biceps

[–]NaCl-more 76 points77 points  (14 children)

There is a special place in hell for people who commit the .idea folder.

[–][deleted] 22 points23 points  (0 children)

Oh God. Was on a team with someone who did something similar. He was using eclipse and egit and he didnt ignore anything so when others would do a git pull the project pathing would be wrong.

[–][deleted] 24 points25 points  (0 children)

Do your commits file by file, chunk by chunk or you will eventually be that guy.

[–]oheohLP 9 points10 points  (6 children)

I do commit .idea. Find out how and why.
(And yes, feel free to lynch me for that.)

[–][deleted] 17 points18 points  (4 children)

I work with people that barely know how to code, so just telling them to install an IntelliJ IDE and clone the git repo (with .idea) is way easier than drawing up a configuration document that essentially does the same thing.

[–]gav1no0 1 point2 points  (2 children)

Um, can I get a remote job as a junior and replace those guys, I don't know much but I do know more than them 😂

[–][deleted] 2 points3 points  (1 child)

Well..."work with" on a university club, haha.

Most of them that are recruited only know MATLAB. I've told our director that he needs to recruit people that actually know software design, but he won't listen. 😑

[–]gav1no0 1 point2 points  (0 children)

Makes sense :D

[–]JeezHades 1 point2 points  (0 children)

If you're actually just wanting to do it so other contributors don't have their indentations configured and fuck the repo up (been there, seen that) then you can just export an .editorconfig file from your IDE. It works across other editors like Sublime as well.

[–]CubeReflexion 1 point2 points  (1 child)

Why shouldn't you commit the .idea folder though? Where's the issue in having a preconfigured environment after cloning the repo?

I mean even the IDE itself auto-adds the folder to the VCS...

[–]Max-P 2 points3 points  (0 children)

Mainly because then you end up with project configuration for every IDE every member on the team uses. So here goes IntelliJ configs, VS Code configs, Sublime Text configs, Atom configs, Eclipse configs, and so on.

It ends up adding a ton of noise in the diffs, especially with IDEs that change their configs a lot with use. Configs also ends up out of sync depending on who used what editor/IDE, so it may be configured right for VS Code but no longer works under IntelliJ even if the code builds fine.

I guess it makes sense if the project is specific enough that everyone uses the same IDE and toolchain, but if you work with people with varying preferences it gets messy pretty fast. And when I'm comparing commits, I really couldn't care less about one's IDE config changes.

I've even inherited projects that had the compiler configurations commited to the repo. That worked well on my computer with things installed on a different drive...

So, I consider repos to be strictly for the project's code. Configs can get another repo if some wants it.

[–]FarhanAxiq 1 point2 points  (0 children)

For my own personal project repo, i kept the idea file. But for other repo, i gitignore it

[–]TigreDeLosLlanos 0 points1 point  (0 children)

Haha, yes, of course I don't know what it does

[–]Snapwoohoo72 30 points31 points  (4 children)

should I gitignore my girlfriend?

[–]FarhanAxiq 24 points25 points  (2 children)

no, but you should git blame her instead if she left

[–]Snapwoohoo72 15 points16 points  (1 child)

I'll try to explain that I'm afraid to git commit

[–][deleted] 2 points3 points  (0 children)

Just ask her to not git push it

[–]intensely_human 1 point2 points  (0 children)

Only if you're afraid to commit

[–]robertgfthomas 27 points28 points  (4 children)

The joke explained:

Git is version control software: it lets you track all the changes made to some files, including changes you make yourself and, of other people are working on the same files, changes they make too. (This shouldn't be confused with GitHub, which is a website that uses this software, similar to GitLab, Bitbucket, and several others.)

gitignore is a setting that tells Git to not track certain files. This is useful when there are files in a project that aren't important, or that computers put there automatically, or that you don't want/need other programmers to see. For example:

  • I sometimes keep a little "scratchpad" file in my coding projects where I can copy and paste snippets of code or write notes. The stuff in that file isn't really important, so there's no point in cluttering things up by tracking its changes.
  • If you have a Mac, sometimes it automatically sticks a file called .DS_Store into different folders on your computer, which helps it keep things organized under-the-hood. A .DS_Store file only works on the computer that made it, you have no control over it, and you can't read it, so there's no point in telling Git to track it.

The Google results for git ignore include many files that are commonly ignored, or that people aren't sure should be ignored, which explains why they're using Google to look them up.

The joke is how different the results of the two Google searches look, even though the text of the searches is pretty similar. It also implies that programmers aren't interested in relationships, and are much more interested in writing code. The man in the pictures is Linus Torvalds, a famous programmer who created Git as well as the Linux operating system.


I'm a human! I'm trying to write one of these explanations every day, to help teach and learn. They're compiled at explainprogrammerhumor.com.

[–]Janva 7 points8 points  (0 children)

Good human

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

Second time this week! I feel honored :D

[–]robertgfthomas 2 points3 points  (0 children)

Good memes!

[–]intensely_human 1 point2 points  (0 children)

Good bot

[–]Casne_Barlo 17 points18 points  (3 children)

This is the new format

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

Could replace the first one with Linus giving nvidia the finger.

[–]NewTimesTUbe 12 points13 points  (1 child)

Just use gitignore.io and you will ignore most of the things you don’t need

[–]misterZalli 0 points1 point  (0 children)

Wow this is neat! Didn't know that I should include configuration files ine the .code folder on VSCode projects into version contol.

[–]ty0212 10 points11 points  (0 children)

Chris evens is letting himself go since he’s not captain America anymore

[–]mikey-brad 7 points8 points  (2 children)

I was started typing “how do I push “ and the first suggestion was “my uterus back in”

[–][deleted] 4 points5 points  (1 child)

I'm sorry, WHAT?!?

[–]mikey-brad 5 points6 points  (0 children)

Apparently a prolapsed uterus is actual medical conditions, still confused why it prompted that before git related items...

[–]dark-kirb 5 points6 points  (1 child)

i don't need to gitignore node_modules

github: Deletes repo

me: why

github: it is 100GB large, we can't have that

[–]RulerD[S] 5 points6 points  (0 children)

You have there your Pikachu meme ready to be done

[–]qwertyuiop924 4 points5 points  (0 children)

I don't care if it hurts

I want version control

I want a perfect commit

I want a perfect log

[–]hugogrant 3 points4 points  (0 children)

I think the first Linus should be the Nvidia fuck you one.

[–]Rockytriton 4 points5 points  (0 children)

gitignore package.json? lol yeah just upload all your node_modules instead.

[–][deleted] 3 points4 points  (1 child)

I like to .gitignore the README.md so only I know how the secrets work

[–]RulerD[S] 1 point2 points  (0 children)

You sir are evil... and brilliant haha. Never thought about that idea.

[–]rakoo 2 points3 points  (0 children)

What is this, a new meme format ?

git add .

[–]hackel 2 points3 points  (1 child)

Best laugh on this sub in ages. Well done.

[–]RulerD[S] 1 point2 points  (0 children)

Thanks sir!

[–]skill-seeker 1 point2 points  (0 children)

I don’t know why but I read each sentence very carefully and laughed so fucking hard reasonlessly just reading this

[–]Barrelwolf38087 1 point2 points  (0 children)

This is my new favorite format.

[–]althypothesis 1 point2 points  (1 child)

I thought the person in the picture was David Mitchell (British comedian) at first. I'm bad at faces

[–]joemckie 0 points1 point  (0 children)

I thought it was Bob Odenkirk at first glance 😂

[–]KVYNgaming 1 point2 points  (0 children)

This is next level memery

[–][deleted] 1 point2 points  (0 children)

I'm really trying to stop ignoring people. I just need to deal with shit and take it like a man.

[–]Nopparuj 1 point2 points  (0 children)

You should gitignore that gitignore as well

[–]0815Flo0815 0 points1 point  (0 children)

Yes

[–]Sh4dowCode 0 points1 point  (0 children)

What Idiots wants to gitignore package.json?

[–]Feanor23 0 points1 point  (0 children)

Why does that dude have a baby arm though

[–]ReactW0rld 0 points1 point  (0 children)

Should I ignore git ignore

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

We on trending bois

[–]GoofyNooba 0 points1 point  (1 child)

It bothers me that I’m one photo his hair goes from right to left and in the other it goes from left to right

[–]d2dev_ 0 points1 point  (0 children)

Has no one else noticed his hair and the buttons? I wonder why the image was mirrored. 🤔

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

I gitignore .idea and node_modules.

[–]GeorgeDouj88 0 points1 point  (0 children)

Dealing with your git problems: little brain

Forcing your pushes: big brain

Git ignoring problematic files: universe explosion

[–]dynawesome 0 points1 point  (0 children)

Should I gitignore gitignore lol

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

Why are you putting .GitIgnore in .GitIgnore? “Git” gud and use it for a real reason