First push of Android Studio in Git - android

Question partially related with gitignore file.
Now when you create an Android project, Android Studio creates .gitignore with your project.
BUT it does not help, these files would be ignored if your code is already in git repository and ignored files ARE NOT already pushed.
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
Now i create a project, Android Studio creates tons of other files including , .idea .IML and so on and i have no idea how can i clean these irrelevant files and folder so i can push clean code to he repository.
Should i do this manually

if ignored files are already in your repository then you should cut them to a new folder outside repository (ex. desktop) then commit deleted files and then turn them back to repository ! this time they will not been tracked by git because they are in your .gitignore file

You can use git rm to untrack files without removing them if you have access to a terminal with git.

Related

How to ignore .idea and .gradle files while commit to git [duplicate]

This question already has answers here:
How do I make Git forget about a file that was tracked, but is now in .gitignore?
(33 answers)
Closed 5 months ago.
I am try ignore the .idea and .gradle folders from android project while commit the code. I already added .idea and .gradle on the .gitignore file inside the app folder.
while run the command git status, It shows the files inside .idea and .gradle are showing in
Changes not staged for commit:
Here is my .gitignore file.
# idea files
.idea/
# Gradle files
.gradle/
/build
To add already tracked file in gitignore you need to delete that file from cache. To delete from cache use this command
git rm --cached <file>
Check documentation .
To remove folder from cache use
git rm -r --cached <folder>
if you've already commited before making the .gitignore,
your .gitignore won't be taken into account for the file already commited.
follow this link for more info :
.gitignore after commit

Should I version app/build files in Android Studio?

I'm new to Git and Android development and I could not find an answer to this question.
When I build a project in Android Studio a lot of files are created in the folder app/build.
I guess I don't need that files, but before ignoring them in the .gitignore, I would like to be sure to not mess my repo since from the first commit :D
I checked this question, but I cannot see in the example .gitignore the folder app/build.
Should I add it to my .gitignore?
P.S. I'm using Android Studio 2.2.3, if relevant
I guess I don't need that files, but before ignoring them in the .gitignore I would like to be sure to not mess my repo since from the first commit :D
You don't need build files in your repo.
Usually .gitignore file contains /build.
I checked this question but I cannot see in the example .gitignore the folder app/build.
You can place another one .gitignore file to app directory, the content of this file also contains /build.
/project
.gitignore
/app
.gitignore
If I copy/past the example .gitignore (which contains build/ ) in the app/ folder, build files are not ignored.
That would be because those files are already tracked.
Try:
cd app
git rm --cached -r build/
git add .
git commit -m "record build content deletion"
git push
Then app/build will be ignored.
Have a look at gitignore.io for generating gitignore files

How to keep library files out of github in android?

How do I keep library files out of my github repo yet still have them work if someone downloads my code? I get about 600 "changes" each time I make a small change to my code! Also if it changes anything I am using github desktop (not through cmd). Thanks in advance!
you need to use git ignore to ignore your build folders from updating with git. git ignore helps you to make a blacklist of items you dont want to commit everytime.
you can see how to make a git ignore file in below:
How to create .gitignore file
I guess you see changes to the workspace files modified by Android Studio / IntelliJ in the .idea folder. These files are automatically re-generated if you remove them and should be private to each user, i.e. not uploaded to source control with git.
Step by step fix
Close Android Studio
Remove the .idea folder in your project root (or backup elsewhere for now)
in the .gitignore file in the root of your project, add a line containing just .idea to ignore the folder and its content when you use git
Commit changes to git which should be the removal of the .idea folder & the .gitignore change
Open Android Studio, re-import you project
.idea folder is now regenerated and private to each git user
Run git status to verify

Gitignore not ignoring some build files in Android library

I have an Android library and for some reason, the files and folders I have specified in my .gitignore are not being ignored.
I have tried modifying my .gitignore and also following these steps, but this doesn't change anything.
Here is my top-level .gitignore (which can also be found on the GitHub repo):
# Gradle files
.gradle/
build/
*/build/
# Local configuration file (sdk path, etc)
local.properties
# IntelliJ
*.iml
/.idea
The module with the build folder that isn't being ignored has the following .gitignore:
/build/
I'm not sure why the build directory isn't being ignored, as it is being ignored in my sample app module, and in the top-level directory.
Also, I did commit changes to some files in the build directory when I updated versions of my library, if that's important.
This answer on Stack Overflow helped me solve my issue.
Here is part of that answer:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
You must remove the first / in your lower level gitignore before build, it will work then.
Also, in top level, you only need this: build/ and then no lower level gitignore will be needed.
Add .gitignore file in your project, and set below lines:
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/build
/captures
.externalNativeBuild
.idea
In my case the .gitignore file was placed inside app directory instead of being in root of project directory.
I figured this out by:
Open Project View in Android Studio
Right-click on build folder
Select Git
Add to .gitignore

Which files should I add to SVN ignore for an Android Studio project?

In Eclipse, I had the custom of adding bin and gen directories to SVN ignore. But now, using Android Studio (based on IntelliJ IDEA), which files should I ignore?
I added the following items in my .gitignore, it should be the same for SVN:
gradle
.idea
*.iml
build
.DS_Store (for mac only)
See this IntelliJ IDEA KB article: "How to manage projects under Version Control Systems".
Add to Subversion:
all files under /.idea directory in the project root but ignore workspace.xml and tasks.xml,
all .iml module files.
I've used the following SVN ignore list sucessfully:
.gradle
local.properties
.idea/workspace.xml
.idea/libraries
.DS_Store
build
The ignore should be applied recursively.
Reference: Same question, for git

Categories

Resources