Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone ignoring .gitignore file

my problem is that when I try to do the following command on my terminal:

git clone https://github.com/DheltaHalo/test.git

It also clones the files that are supposed to be ignored by .gitignore.

I've read that if, for example, I have written in my .gitignore file *.txt it should ignore all .txt files, but when I clone it to my desktop it downloads those files as well.

like image 550
DheltaHalo Avatar asked May 16 '26 02:05

DheltaHalo


2 Answers

The .gitignore is considered only when adding (staging) files that are not already staged (except with git add -f).

The process of cloning ignores the .gitignore file.

If a file is added, committed and another commit with the .gitignore is created, the file will still be part of the repository and therefore cloned.

like image 101
dan1st Avatar answered May 18 '26 17:05

dan1st


.gitignore is only meant to ignore files that have not been tracked yet. If your files already are inside your repository, it's now part of history and there's no point of ignoring them at this stage, otherwise the outchecking of your revision would be incomplete.

Note that it won't work the other way neither if you add some already tracked files to .gitignore and alter them. Git won't care about new files but it will still track the ones that are already recorded. If this is what you want to do, you have to perform a "remove" (file deletion) that would apply only on the index, without touching the working directory. This can be done with: git rm --cached [file].

like image 33
Obsidian Avatar answered May 18 '26 18:05

Obsidian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!