I want to change the gitignore, but not everyone on the team wants these changes. How can a user have their own specific git ignore file?
Asked
Active
Viewed 3.3k times
148
-
A very concise answer is actually provided in the [documentation](https://git-scm.com/docs/gitignore#_description). – djvg Sep 27 '21 at 07:44
5 Answers
157
You can create your own .gitignore using
git config --global core.excludesfile $HOME/.gitignore
Then put your desired entries in that file.
Pedro Romano
- 10,519
- 3
- 42
- 49
Dave Kincaid
- 3,720
- 3
- 21
- 31
-
24If you don't want it to be global, you can put your `.user_gitignore` file under repo's `.git` directory and add it with `git config core.excludesfile .git/.user_gitignore` – orad Jan 28 '15 at 20:36
-
8[Pro-tip from Tim Pope](https://github.com/tpope/vim-pathogen#faq): use `~/.cvsignore` because utilities like rsync will use this file as well. – Peter Rincker Mar 06 '15 at 17:57
-
4
-
3Take in account that orad's/Dave's suggestion will overwrite the default of `core.excludesfile` pointing to your global ignore file ie: `~/.gitignore`. If you want to preserve global exclusions and have repository specific exclusions as well, @grzuy's answer is the way to go – sgimeno Mar 01 '18 at 10:32
-
1On Git for Windows, `$HOME/.gitignore` did not work correctly for me, but `~/.gitignore` did. – Soren Bjornstad Oct 28 '19 at 18:12
124
For user-specific and repo-specific file ignoring you should populate the following file:
$GIT_DIR/info/exclude
Usually $GIT_DIR stands for:
your_repo_path/.git/
grzuy
- 4,393
- 2
- 19
- 16
-
9For those confused about the path: `your_repo/.git/info/exclude`. The file is formatted like a standard [.gitignore](https://git-scm.com/docs/gitignore) file. – Stevoisiak Nov 07 '17 at 15:37
-
7If your file already contains unstaged changes you may need to run `git update-index --skip-worktree [
...]` (from https://hashrocket.com/blog/posts/ignore-specific-file-changes-only-on-current-machine-in-git) – Daniel Olivares Jan 17 '18 at 01:55
41
In their .gitconfig:
[core]
excludesfile = ~/.global_gitignore
That way, they can ignore certain types of files globally. Each user can have their own global ignore file.
Rafe Kettler
- 73,388
- 19
- 151
- 149
-
2You can access the `.gitconfig` by running `git config --local -e` in the repo you want – Peter Graham Jul 14 '17 at 19:46
7
For example, you want ignore ~/some/path/.idea folder:
# 1. Add .idea to user specific gitignore file
echo .idea > ~/.gitignore
# 2. Add gitignore file to gitconfig
git config --global core.excludesfile ~/.gitignore
Sergey Zhigalov
- 901
- 7
- 3
5
As indicated in Atlassian's .gitignore tutorial, you could also use your repo's <repo>/.git/info/exclude file that you can easily edit with any text editor. It works the same as .gitignore.
I could easily ignore my intelliJ files, personal dockerfiles and stuff only I need to work with.
-
Yes! Edit the `exclude` file to get *repo specific* ignore of files or file patterns. Great for scripts that I want to use for that repo and _store_ in that repo, but don't want committed to the project at large, and don't want cluttering the `.gitignore` file that is shared by everybody. – Purplejacket Feb 08 '21 at 23:51