Is it possible to add the .gitignore
file to .gitignore
itself?
.gitignore
Doesn't work though
I don't want to see it in edited files
Is it possible to add the .gitignore
file to .gitignore
itself?
.gitignore
Doesn't work though
I don't want to see it in edited files
The .gitignore
file's purpose is to prevent everyone who collaborates on a project from accidentally commiting some common files in a project, such as generated cache files. Therefore you should not ignore .gitignore
, since it's supposed to be included in the repository.
If you want to ignore files in just one repository but want to avoid committing the ignore list (for example for personal files) you can add them to .git/info/exclude
in that repository.
If you want to ignore certain files on every repository on your machine you can create the file ~/.gitignore_global
and then run
git config --global core.excludesfile ~/.gitignore_global
.git/info/exclude
to ignore your .gitignore
file locally if you're like in my siguation. More generally, you can generally do git rm --cached .gitignore
but it was advised that's a bad idea. Full answer here. What a nonconstructive and obstructive comment from vader here. They were probably having a bad day. Nonetheless, I agree that doing this will cause long term issues, especially if you push to your team's remote –
Melson A .gitignore can ignore itself if it's never been checked in:
mhaase@ubuntu:~$ git --version
git version 1.7.9.5
mhaase@ubuntu:~$ git init temp
Initialized empty Git repository in /home/mhaase/temp/.git/
mhaase@ubuntu:~$ cd temp
mhaase@ubuntu:~/temp$ touch .gitignore foo bar baz bat
mhaase@ubuntu:~/temp$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# bar
# bat
# baz
# foo
mhaase@ubuntu:~/temp$ echo "foo" >> .gitignore
mhaase@ubuntu:~/temp$ echo ".gitignore" >> .gitignore
mhaase@ubuntu:~/temp$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# bar
# bat
# baz
nothing added to commit but untracked files present (use "git add" to track)
If you check in .gitignore (before you tell it to ignore itself), then it will always show up in git status, even if you later modify it to ignore itself.
.gitignore
for working with git-svn
, which no-one should see. So I just added it to itself and it just worked. But then I googled to see if some uptight people will explain to others how this is "bad". This answer should be accepted, and then I would upvote the .git/info/exclude
suggestions also. So it just needs to be untracked... Not very surprising, at least if you've ever been "subverted" (svn). –
Stendhal .gitignore
file got backup first. Then I use git rm .gitignore
and commit that change. At last, add and commit .gitignore
file again with rule for .gitignore
. It works! –
Grandmother git rm --cached .gitignore
. –
Temptress .gitignore
ignores untracked files. If the .gitignore
file itself is untracked, it can ignore itself too. Yes, this violates the original purpose of .gitignore
but that doesn't mean it can't be used this way. –
Snuffy There's not really a good reason to do this. If you want files ignored for your clone only, add them to .git/info/exclude
, not in .gitignore
file.
After you enter .gitignore
in your gitignore file, try the following,
git rm -r --cached .
git add --all
git commit -m "ignoring gitignore"
git push --set-upstream origin master
It should work although like already said, ignoring gitignore can be counter-productive if your repo is shared by multiple users.
git rm -r --cached .
is what I needed to apply the changes in .gitignore
file –
Thirteen Yes you can; you still see it in edited files because it is still tracked by git, and files tracked by git are always marked as modified even if they are in .gitignore. So simply untrack it.
But why not committing or resetting changes that you have on it? It's a much better way to remove it from status... Also be aware that any fresh clone of you repo will have to add its .gitignore
, which can be annoying.
got rm --cached .gitignore
, probably. –
Fidel Adding the folder or files into .git/info/exclude will help us in retaining the folder changes as well as not committing the changes to the repository.
In My case, I had a CMD folder which contained the .bat files, which I wrote to run the commands on the repository.
making the above changes in the .git/info/exclude file helped me in achieving my requirement.
© 2022 - 2024 — McMap. All rights reserved.
.gitignore
is supposed to be part of your repository, listing file patterns that are junk for the project. – Birgit.gitignore
should be part of your repository, so that everyone on your team is ignoring or checking in the same files. Just because.gitignore
is in your code folders somewhere doesn't mean you have to deploy it. – Pedersongit rm --cached .gitignore
and untracking .gitignore – Monarchismmy-local-hack/.gitignore
when no one else should ever see that directory. – Felske