Source tree .gitignore to ignore everything but specific directories Edited

I've seen many examples and they pretty much say the same but for some reason I cannot get it to work using SourceTree.

My folder structure shown below, i want to ignore everything except for folder3 and all it's content, folder2_3_2_1 all it's content and the .ignore file.

 

folder1
folder2
   folder2_1
   folder2_2
   folder2_3
     folder2_3_1
     folder2_3_2
          folder2_3_2_1
             someOtherFile1.php
             someOtherFile12php
             someNewFolder
     folder2_3_3

   folder2_4
folder3
.ignore
somefile.php
somefile2.php

 

in my .ignore I have the following

# Ignore everything
/*


#except for
!.gitignore
!folder3/
!folder2/folder2_3/folder2_3_2/

 

 

Strange thing is, if I don't ignore anything and I'm able to see all my files in my unstaged files panel, if I right click and ignore someOtherFile.php and select the option to ignore everything beneath, it does the opposite, it ignores it's folder (i.e. folder2_3_2_1) and everything within!

 

Sourcetree V 2.3.1.0

Thank you in advance

1 answer

0 vote

Hi David! It looks like you're using the wrong name for the file, it should be called .gitignore not .ignore. Can you fix that and try:

# Ignore everything
/*


# Except for
!.gitignore
!folder3/
!folder2/folder2_3/folder2_3_2/*

Apart from that, keep in mind that .gitignore will prevent untracked files from being added, however git will continue to track any files that are already being tracked. This means, if the files were tracked before, they will continue to be tracked even though you added them now to the .gitignore. To stop tracking a file you need to remove it from the index, you can achieve this with the command:

git rm --cached <file>

The removal of the file from the head revision will happen on the next commit.

 

Lastly, you can try all of this directly in the terminal instead of Sourcetree, so we can determine wether this is some kind of issue in Sourcetree, or the problem is somewhere else :)

Let us know if this helps!

Cheers,

Ana

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

648 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you