I followed this link https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ to push my project to a repo. I noticed that I don't have a gitignore file and that files such as .idea and .iml have been added to the repo. How do I add a gitignore file and delete these from the repo?
You need to add .gitignore file to your project root directory
Get .gitignore file for android from Android.gitignore It contains all possible ignore files which should be ignored from android project
Then follow these git commands to remove files from git repository. Local files will not be deleted
git rm --cached .idea
git rm --cached project.iml
git rm --cached <file_name>
Remove all the files you want to ignore Then add the changes and commit it using following commands
git add .
git commit -m "ignoreable files ignored"
Then if you want to push those changes to remote just use
git push origin master
Edit 1
In case your remote branch has new commits and updated by other contributor you need to fetch it and rebase it before pushing
git fetch origin master
git rebase origin/master
git push origin master
So it will be synced with local branch
You need to add a .gitignore
file at the root of your git repository. In that, you can put as a new-line separated list, the regular expressions of the paths you want git to ignore while looking for changes in your repository.
So for example, your git repo root directory has the following sub directories that you want git to ignore,
{git-root}/project/bin/debug
{git-root}/project/bin/release
You can simply add {git-root}/project/bin/
in your .gitignore
if these two directories are the only ones in your {git-root}/project/bin
sub-directory.
Similarly, if in your {git-root}/project/bin
sub directory, you have another directory tests
and you do not want to ignore that, then you will have to add
{git-root}/project/bin/debug
{git-root}/project/bin/release
to your .gitignore
file.
For an example, this is the .gitignore
file of an android project I am working on. You can observe the syntax:
{project}/app/release/
{project}/app/debug/
{project}/api_objects/
{project}/.idea/caches/
{project}/api/
{project}/.idea/vcs.xml
{project}/.idea/inspectionProfiles/Project_Default.xml
After this, don't forget to add the .gitignore
to your git repo using git add .gitignore
. You can do all this manually or through any of the Git desktop clients like Sourcetree
or Git Desktop
. It is easier to do this using the UI tools I listed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.