Search code examples
android-studiogitignore

is it wrong to add folder like *folder in .gitignore file?


I have 3 flavours in android studio. when I create any flavour apk then release folder with apk(+somefile) generated under respected flavour folder and this considers as an unversioned file for git. because I don't want in git so I added *release in .gitignore file is it the wrong way to do? will it create problem in future?

myApp
    - .gradle
    - .idea
    - build
    - app
        - build
        - flavour1
            -release
                -app-flavour1-release.apk
                -output-metadata.json
        - flavour2
            -release
                -app-flavour2-release.apk
                -output-metadata.json
        - libs
        - src
            - flavour1
                - somefile
            - flavour2
                - somefile
            - main
            - test
            - androidTest
            - .gigignore
            - build.gradle
            - proguard-rules.pro
            - releasekeystore.jks
        - .gigignore
        - build.gradle
    - openCVLibrary3410
        - build
        - src
        - .gigignore
        - lint.xml
    - scanlibrary
        - build
        - src
        - .gigignore
        - build.gradle
    - .gigignore
    - build.gradle
    - somefile..

Solution

  • I wouldn't say it is wrong, but I would recommend you make sure the pattern in the gitignore file fits with your standard project layout as strictly as possible to avoid the case where someone makes a folder later and it is unexpectedly ignored.

    \*release will ignore any file or folder ending in "release" within the same folder as the ignore file. In my projects I often hyphenate special folders like that such as "linux-release" so I would probably use"*-release" in that case to reduce the cases it would match as much as possible.

    All this to say that what you have done shouldn't cause any problems but I would go the extra mile to make sure it is not unpredictable to the rest of your team by being more specific in the pattern now.

    If you'd like, post a better example of your folder structure to offer more direct advice.

    Example of a Different Practice: In many projects i have worked on we put releases in build/release/android and build/release/ios folders. We have build/ in our .gitignore and use these subfolders of build specifically because every dev knows anything in that folder should be the result of a build or byproducts of it, which are not version conrtolled. So our devs know any folder named build, even in another non-src directory is not something probably shouldnt be used for storing files in git.