Search Unity

Github and Unity. Default Unity gitignore not enough?

Discussion in 'Getting Started' started by Sparticus, Oct 30, 2020.

  1. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Hey all,

    When I created a git repo (on github) for my unity game, GitHub offered me a template .gitignore file which I assumed would prevent files that I don't need to backup from being saved in the repo.

    However, even though I may just open the project, make a few changes to a few c# files and play the game.... tons of files are flagged by git as modified....

    Do I need to add more stuff to my gitignore file? Below is an example of all the changed files when I just edited 3 c# files (I assume I can get rid of the log files, not sure about the rest)

    upload_2020-10-30_9-9-38.png

    Here is my gitignore file provided by github

    Code (CSharp):
    1. # This .gitignore file should be placed at the root of your Unity project directory
    2. #
    3. # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
    4. #
    5. /[Ll]ibrary/
    6. /[Tt]emp/
    7. /[Oo]bj/
    8. /[Bb]uild/
    9. /[Bb]uilds/
    10. /[Ll]ogs/
    11. /[Mm]emoryCaptures/
    12.  
    13. # Asset meta data should only be ignored when the corresponding asset is also ignored
    14. !/[Aa]ssets/**/*.meta
    15.  
    16. # Uncomment this line if you wish to ignore the asset store tools plugin
    17. # /[Aa]ssets/AssetStoreTools*
    18.  
    19. # Autogenerated Jetbrains Rider plugin
    20. [Aa]ssets/Plugins/Editor/JetBrains*
    21.  
    22. # Visual Studio cache directory
    23. .vs/
    24.  
    25. # Gradle cache directory
    26. .gradle/
    27.  
    28. # Autogenerated VS/MD/Consulo solution and project files
    29. ExportedObj/
    30. .consulo/
    31. *.csproj
    32. *.unityproj
    33. *.sln
    34. *.suo
    35. *.tmp
    36. *.user
    37. *.userprefs
    38. *.pidb
    39. *.booproj
    40. *.svd
    41. *.pdb
    42. *.mdb
    43. *.opendb
    44. *.VC.db
    45.  
    46. # Unity3D generated meta files
    47. *.pidb.meta
    48. *.pdb.meta
    49. *.mdb.meta
    50.  
    51. # Unity3D generated file on crash reports
    52. sysinfo.txt
    53.  
    54. # Builds
    55. *.apk
    56. *.unitypackage
    57.  
    58. # Crashlytics generated file
    59. crashlytics-build.properties
     
    Ranger-Ori and AldeRoberge like this.
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    The default file should be enough.
    Make sure it's at the root of your project directory - it looks like it isn't finding your Library folder to exclude.
     
    aeo237, br3ndanl8n and AdrianMesa like this.
  3. n8mcclain

    n8mcclain

    Joined:
    Feb 19, 2014
    Posts:
    1
    I know this is old but I think the issue is the slash in front of the folders...
     
    JBKac, owndbyu777 and loprez like this.
  4. JBKac

    JBKac

    Joined:
    Sep 16, 2021
    Posts:
    1
    changing /[Ll]ibrary/ to **/[Ll]ibrary/ will fix the issue. also works for nested subfolders (meaning if you have multiple unity projects in one repository and place .gitignore in the root folder of the repo)
     
    vrkitten and albert203 like this.
  5. Jeper

    Jeper

    Joined:
    Nov 19, 2021
    Posts:
    2
    I did this, and it ignores 8000+ files I untracked with git rm -r --cached, but it still tracks files like Library/ArtifactDB and Library/PackageManager/ProjectCache. Is there a solution to make it ignore those files?
     
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    @Jeper: Using /[Ll]ibrary/ will exclude everything in the Library folder, including subdirectories. But this also assumes your gitignore will be at the root of your project (in the same folder as your csproj files, the Assets, Library, Packages folders, etc) and that the git repo is at the project root as well.

    I've used the standard Unity gitignore for years and have never had an issue with stuff being included that shouldn't be.
     
    WayneJP likes this.
  7. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    I think you are creating your Unity project in a subfolder of the repo root. In that case, one of these should solve the problem:

    1. Append the folder name to the anchored folders in your gitignore:
    /MyUnityProject/[Ll]ibrary/
    instead of
    /[Ll]ibrary/
    .

    2. Move the gitignore to the folder that contains the unity project. You may need another gitignore at the root depending on your setup.

    I do not recommend adding double asterisks at the beginning of the patterns (
    **/[Ll]ibrary/
    ) as it will ignore any folder named Library or library anywhere in the project.

    See this question I asked on StackOverflow for a partial explanation of why this is happening: https://stackoverflow.com/questions/53695558/gitignore-pattern-doesnt-work-without-double-stars
     
  8. dre38w

    dre38w

    Joined:
    Nov 18, 2009
    Posts:
    137
    Hello. The default gitignore isn't working for me either. I know for a fact it is in my root folder and SourceTree is still reading every single file in the Unity folder. I'm using the most up to date Unity version and have Visible Meta Files, Force Text selected. I also tried the first method suggested by @starikcetin and no luck. Is there something I'm missing?
     
  9. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    If the files are already added to git, you need to manually tell git to forget them. Make sure to commit all you changes before running these.
    Code (CSharp):
    1. git rm -rf --cached .
    2. git add .
    3. git commit -m "git index reset"
     
    Last edited: Feb 24, 2022
  10. dre38w

    dre38w

    Joined:
    Nov 18, 2009
    Posts:
    137
    Wait, I'm confused. So I have to type in the terminal every single time I and the team commits? Is it a directory that I can reference or do I have to type in every single file I want to ignore? That's....a lot of files.

    Also, git rm --rf --cached didn't work. It gave me an error. I'm using Source Tree and Terminal is Git Bash.
     
  11. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    There is a
    .
    at the end. Also you don't have to put dot, you can also write the path to a file or folder. Example:
    Code (CSharp):
    1. git rm -rf --cached PATH/TO/FILE/OR/FOLDER
    2. git add PATH/TO/FILE/OR/FOLDER
    3. git commit -m "git index reset"
    Dot just means current directory.

    Also it should be
    -rf
    not
    --rf
    . I miswrote it.
     
    Mr_Htet likes this.