Set a custom default gitignore file in Android Studio

Android Studio includes a .gitignore file with each new project that is created. This file is a good start but it is missing a lot of things that you may need to add as your project grows.

I create a lot of Android projects to test out small pieces of the SDK in isolation. As a matter of habit the first thing I do for each project is initiate a git repository so that I can conduct my tests and revert my changes while working towards an optimal solution.

For some reason I never bothered to set a custom .gitignore file. After the creation of each project I would then manually copy my default file into the new project. Today when I went to create a new project it occurred to me that I should automate this step (after hundreds of projects).

Updating the default file

Fortunately updating the default file is straightforward.

1. Locate the NewAnddroidProject template in your Android Studio installation.

I am running Android Studio 3.3 on Linux. My install location is /opt/android-studio/. The full path to the template directory is /opt/android-studio/plugins/android/lib/templates/gradle-projects/NewAndroidProject/root.

2. Edit the the project_ignore file. Put the contents of your desired ignore file here.

That is it! You can view my typical .gitignore file here but there are several great examples out there that you can use as the foundation for your specific workflow and needs.