$ cat ~/.gitconfig [core] editor = vim excludefiles = /home/augustin/.gitignore $ cat ~/.gitignore toto $ mkdir git_test $ cd git_test/ $ git init $ touch toto $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # toto nothing added to commit but untracked files present (use "git add" to track) $ git --version git version 1.6.3.3
Why isn't toto being ignored?
Other settings in ~/.gitconfig are taken into account (colors, editor).
gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.
You can set up a global . gitignore file that lists files that will be ignored on all Git projects. This is the preferred way of ignoring editor artifacts, toolchain log files, OS files, and other miscellaneous crap.
Use Git update-index to ignore changes Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.
1 Answer 1. The gitignore man page doesn't mention of a global gitignore file. But if the latter doesn't work, that might be because those files were previously added to the Git repo, in which case you must rm them.
Sometimes .gitignore files don't work even though they're correct. The reason Git ignores files is that they are not added to the repository. If you added a file that you want to ignore before, it will be tracked by Git, and any skipping matching rules will be skipped. Git does this because the file is already part of the repository.
To make .gitignore work, you have to ensure that the file should not be part of the repository yet. The file won’t be ignored once it is already added to the repository. Even if you have changed its name or rule in the .gitignore file, Git can’t ignore it. This is because Git can only ignore the untracked files.
First, create a .gitignore file for your global rules. Most people keep this in their home directory. Next, open it with your text editor of choice and add whatever files and folders you always want to ignore. Here’s what my global configuration looks like:
git config --global core.excludesfile ~/.gitignore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With