Sourcetree adding files in global .gitignore, not in repository .gitignore

76.5k views Asked by At

I am using SourceTree for my GIT repositories.

Today I need to ignore some files; when I added these files to ignore list from SourceTree's "Ignore file" menu and check local .gitignore file, the ignored files are not listed there. Instead these are listed in the global .gitignore.

How can I get SourceTree to add the files to the repository-specific .gitignore?

4

There are 4 answers

2
acanby On BEST ANSWER

When you choose to ignore a file that is modified etc, SourceTree will bring up the following dialogue:

Ignore modal dialogue

Instead of choosing the "global ignore list", select the "this repository only" option.

0
UKDataGeek On

Easiest way to edit the individual, is right click the file. Click Ignore and select the option to ignore just in this repository then you will see a new file called .gitignore in the list.

If you have accidentally already added them to the list. You can delete them by going to Sourcetree - > Preferences -> Git menu option. See below. Sourcetree options

As a quick tip - I find that github has a great selection of starter github ignore files which I find really useful to start a new project

Eg: https://github.com/github/gitignore

0
Greg7000 On

In my case, at some point in time, Sourcetree started using the gitconfig from C:\Program Files\Git\mingw64\etc\gitconfig instead of using C:\Users\yourUser.gitconfig.

Once I added the following line in this gitconfig, it resolved my issue on Sourcetree:

[core]
    safecrlf = false
    excludesfile = C:\\Users\\<YOUR_USER>\\Documents\\gitignore_global.txt

Please note that on my side the global ignore setting from Tools/Option/Git/ does not seemed to be considered by Sourcetree, therefore I don't even need to change it.

0
Thar On

I had the opposite issue, local worked but global did not work, for that you also need to create the global ignore file by running the command line

git config --global core.excludesfile ~/.gitignore_global

Else source tree will not save this in the preferences.

Then follow the acanby solution.