Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 656
Irfan DANISH Avatar asked Jun 18 '15 06:06

Irfan DANISH


People also ask

How do I add files to Gitignore in Sourcetree?

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.

Should .gitignore be added to repository?

Normally yes, . gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something. In those cases you probably don't want to force that on anyone else.


3 Answers

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.

like image 130
acanby Avatar answered Oct 19 '22 10:10

acanby


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

like image 44
UKDataGeek Avatar answered Oct 19 '22 10:10

UKDataGeek


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.

like image 2
Greg7000 Avatar answered Oct 19 '22 09:10

Greg7000