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?
5 Answers
You can create your own .gitignore using
git config --global core.excludesfile $HOME/.gitignore
Then put your desired entries in that file.
-
30If you don't want it to be global, you can put your
.user_gitignore
file under repo's.git
directory and add it withgit config core.excludesfile .git/.user_gitignore
– oradJan 28, 2015 at 20:36 -
9Pro-tip from Tim Pope: use
~/.cvsignore
because utilities like rsync will use this file as well. Mar 6, 2015 at 17:57 -
5@orad I think your comment deserves to be its own separate answer. Nov 7, 2017 at 15:34
-
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– sgimenoMar 1, 2018 at 10:32 -
1On Git for Windows,
$HOME/.gitignore
did not work correctly for me, but~/.gitignore
did. Oct 28, 2019 at 18:12
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/
-
10For those confused about the path:
your_repo/.git/info/exclude
. The file is formatted like a standard .gitignore file. Nov 7, 2017 at 15:37 -
10If your file already contains unstaged changes you may need to run
git update-index --skip-worktree [<file>...]
(from hashrocket.com/blog/posts/…) Jan 17, 2018 at 1:55
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.
-
4You can access the
.gitconfig
by runninggit config --local -e
in the repo you want Jul 14, 2017 at 19:46
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
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. Feb 8, 2021 at 23:51