First of all, let’s figure out
What is .gitignore file?
.gitignore is a file which contains file or pattern which should ignore by git tracking. It’s usually used to avoid committing transient files from your working directory that are not useful to other collaborators, such as compilation output files, tempory files or IDE created files etc. You can read more about .gitignore from this link. https://git-scm.com/docs/gitignore/2.9.1
How to add .gitignore in Android Studio easy way
It’s pretty easy to add .gitignore file in Android Studio. (or any IDE which uses IntelliJ such as phpstorm, pycharm etc.) But first, you need to install .gitignore plugin for IntelliJ IDEA. If you don’t know how to install plugin in IntelliJ refer this link https://www.jetbrains.com/help/idea/installing-updating-and-uninstalling-repository-plugins.html
Let’s Get to work.
We are going to auto-generate .gitignore using .gitingnore plugin. Right-click on the project folder and follow image path.
The Select Android from the Left panel and Click on Generate Button.
Android Studio will generate .gitignore files and patterns which contains all the file need to ignore. But for our own safety double check the file before you commit.
If you Don’t like to use plugin for creating .gitignore you can create .gitignore using github instructions.
Add .gitignore Manually
Go to https://github.com/github/gitignore. Then you can see all the default .gitigonre files used by git.
You can open your relevant .gitignore file and copy the content, then create a file named .gitignore in your project. (Please keep in mind to remove the file extension and rename as .gitignore) then paste the content into your file and save (You don’t need to save in IntelliJ because it normally saves the files for us 🙂 ).
Now your .gitignore is ready to roll 😀