There are many examples of .gitignore files for Android Studio projects, some of them have .idea files in them and others don’t. Let’s figure this out.
What’s the .idea folder?
When using IntelliJ IDE (or another IntelliJ based IDE like Android Studio), the .idea directory contains a set of configuration data. Project settings are stored with each specific project as a set of xml files.
It contains many files and configuration values, it includes assets information, caches, code styles, dictionaries, project type information, workspace settings among many other data.
For more information take a look at this article: Deep dive into .idea folder in Android Studio.
Should the .idea folder be kept under version control?
This is the debate area, this official article states that all files under the .idea directory in the project root except the workspace.xml, usage.statistics.xml and tasks.xml files which store user specific settings should be under version control.
This may be helpful if you are working in a team that needs to be synchronized in terms of IDE configuration or want to share project configuration contained in these files, however, I personally do not like to make my repos IDE-dependent so I prefer not to include the .idea folder in my repos and ignore it from my initial commit, instead I use maven or gradle files to make configuration and dependencies available to everyone.
How to remove the .idea folder from your repo?
So if you have already committed your .idea folder to your repo you can remove it pretty easily.
- Add the .idea folder to your .gitignore file in your master branch (You can do this by adding .idea to a new line in your .gitignore file) and commit the change.
git commit -m "Add .idea folder to .gitignore"
- In your current branch, check this file out from master to get the updated file. Skip this step if you’re working in your master branch.
git checkout master -- .gitignore
- Remove the .idea folder from the git tree.
git rm --cached -r .idea
- Commit this change.
git commit -m "Remove .idea folder from repo"
Your project is now free from the IDE chains.