asdsadasds
asdsadasds

Reputation: 1993

Can I make a user-specific gitignore file?

I want to change the gitignore, but not everyone on the team wants these changes. How can a user have their own specific gitignore file?

Upvotes: 199

Views: 53095

Answers (6)

Dave Kincaid
Dave Kincaid

Reputation: 4180

You can create your own .gitignore using

git config --global core.excludesfile $HOME/.gitignore

Then put your desired entries in that file.

Upvotes: 189

dmacduff
dmacduff

Reputation: 131

Global (user) scope ignore

Per gitignore Documentation, a user-level excludesfile default exists without editing git config --global core.excludesfile:

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

So one only need create (and populate) the relevant file, usually $HOME/.config/git/ignore (and possibly path):

if [ -z "${XDG_CONFIG_HOME}" ] ;
then 
    echo "XDG_CONFIG_HOME unset or empty, try \$HOME" ;
    if [ -z "${HOME+x}" ]
    then
        echo "Variables for default not set"
        echo "use explicit \`git config --global core.excludesfile EXCLUDES_FILE\`"
    else
        echo using \$HOME
        mkdir -p "$HOME/.config/git" && touch "$HOME/.config/git/ignore"
    fi
else
    echo using \$XDG_CONFIG_HOME
    mkdir -p "$XDG_CONFIG_HOME/git" && touch "$XDG_CONFIG_HOME/git/ignore"

fi

Caveat: This configuration is implicit rather than explicit. Consider setting git config --global core.excludesfile to the chosen file, even if it is a default.

Repo scope user-specific ignore

Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the $GIT_DIR/info/exclude file.

So from the root of the repo, edit .git/info/exclude

Upvotes: 8

obscure18
obscure18

Reputation: 349

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.

Upvotes: 10

Sergey Zhigalov
Sergey Zhigalov

Reputation: 1219

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

Upvotes: 11

grzuy
grzuy

Reputation: 5041

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/

Upvotes: 161

Rafe Kettler
Rafe Kettler

Reputation: 76955

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.

Upvotes: 44

Related Questions