20

I am developing an app and I must take that project to GitHub. Now, I must make gitIgnore file. I know that file is used to ignore some specified files from my project. I used gitIgnore.io service and I received generated file. This is my gitIgnore file:

# Created by https://www.gitignore.io/api/android ### Android ### # Built application files *.apk *.ap_ # Files for the ART/Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ # Android Studio captures folder captures/ # Intellij *.iml .idea/workspace.xml # Keystore files *.jks ### Android Patch ### gen-external-apklibs 

But I don't know were to copy this, and where to put that in my Android project. Could someone help me?

I copied this file into my gitIgnore file in Android Studio, but when I have pushed that project on gitHub my gitnigore file looks like this:

*.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store /build /captures 

So, that files that I copied into Android Studio are not here. What is the problem?

3 Answers 3

32

Normally when creating a new project the gitignore file is generated for you.

Here is the correct .gitignore file.

*.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store /build /captures 

This is were you have to put it.

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks man. Just another question: What do you think, is gitignore.io service is good enough for making .gitignore files? Other words, is all that I need to ignore is generated here?
The Android Studio is generating the gitignore every time you create a new project. If you are working on an existing project copy and paste the text above. You don't need anything else. gitignore.io is awesome but you don't need it.
But how about the build folder in 'app' module?!
But the project can have modules for other platforms, eg. google app engine, so putting the .gitignore in root of project mean that you have your Android .gitignore rules applying to non-Android code (and vica-versa since you'd need to pile the rules for all modules into 1 file).
anybody know why there is also a separate gitignore in the 'app' directory?
|
10

.gitignore file must be in the root directory of the project not just in android projects but in any project types

I hope my answer would be useful

6 Comments

Well I had bad explained my problem. When I download this file from gitIgnore service what exactly should I do after that?
just copy the content of file and make file in project root called .gitigniore in project root and git will ignore any file that match the expressions in this file
I copied this file next to gradle files in my project end when I wanted to rename it to the ".gitignore" then I receive this message "The name “.gitignore” is already used in this location. Please use a different name."
the git .gitignore is a hidden file just show hidden files in your system and edit the file by copying the content generated from gitignore.io to the file
I found that file and overwrite it but when i posted project on gitHub my gitignore file looks like this: *.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store /build /captures Is that means that file which I downloaded it did not copied well or what?
|
7

Location
The file should always be placed in the root directory of the project.

Contents
Check out this handy page on Github with template gitignore files for Android and other languages - they represent best practice and are regularly updated.

1 Comment

Perfect. Thank you.