Not working properly .gitignore when versioning an Android project


I still can not have a .gitignore file that can help my code versioned in git for an Android project, if I modify a class or something very simple modifications are made in unnecessary files like tests.

Annex my .gitignore too.


# Built application files

# Files for the ART/Dalvik VM

# Java class files

# Generated files

# Gradle files

# Local configuration file (sdk path, etc)

# Proguard folder generated by Eclipse

# Log Files

# Android Studio Navigation editor temp files

# Android Studio captures folder

# Intellij

# Keystore files

# External native build folder generated in Android Studio 2.2 and later

# Google Services (e.g. APIs or Firebase)

# Freeline

Thank you.

asked by Rogelio Sanchez 26.10.2017 в 17:11

3 answers


Review the documentation , where you specify:


A file gitignore intentionally specifies files without   tracking (untracked files) that git should ignore. Keep in mind that all gitignore files really only refer to files that have not yet been tracked by git

Therefore, what is defined within .gitignore applies to files without follow-up, in your case the files that I see mainly are those that are within the directories /build are already marked for tracking.

To take the changes made in the .gitignore do the following:

Perform committing pending changes and remove modified index files:

git rm --cached -r .

save changes:

git add .

and commit:

git commit -m ".gitignore funcionando!"

Reviewing your file .gitignore , I can suggest some changes:

  • *.iml change by **/*.iml to search all directories for files with the .iml extension

  • .gradle by .gradle/ correctly specifies a directory.

  • If you specify /build , you do not have to specify the files *.dex and *.class , since they are inside this directory, the same for the directories bin/ gen/ (in android is /generated ) and out/ (in android is /outputs ), it is not necessary to specify them.

Documentation link

answered by 26.10.2017 / 18:52

Adding the .gitignore file to the directory does not mean that you will ignore it that way. You have to run the following commands so that gitignore recognizes the files that should not be tracked. Remember to commit to the files you have currently or you will lose the changes in those files

git rm -r --cached .
git add .
git commit -m "Reparados archivos no trackeados"
answered by 26.10.2017 в 18:18

Your problem seems to be that the sample-core / build / folder is being versioned

To solve this, in addition to the .gitnore file that you have in the root of your project, you should add an additional .gitignore file within your sample-core folder. The file should have the following content:


As an additional fact, when you create a new project with Android Studio, the IDE automatically generates these two .gitignore files: one in the root of the project and another in the module. Here more information about the structure of projects on Android.

answered by 26.10.2017 в 17:39