My app uses a NASA API to get images from the mars rover. The file where I keep the api key is called Constrant.swift. I tried to hide this file by creating a .gitingore file. I typed Constrant.swift into the .gitignore file and then pressed save and pushed all of the files to GitHub. The problem that I am having is that when I pushed all of the files the Constrant.swift was all pushed and was not ignored. The api key is not that important, but I would still like to know what I did wrong and how to fix it.
The link to the repository is here. As you can see the .gitignore file is still there and has Constrant.swift. However, when you press nasaAPI, the Constrant.swift file is still there. Also I created the .gitignore file before I added the Constrant.swift file. How would I remove this file from GitHub and hide it in the .gitignore file?
First of all, you must also add the folder in where the Constrant.swift is located to .gitignore
, and not only the file name:
nasaAPI/Constrant.swift
Then if the file is already tracked (pushed on remote repository on a previous commit), you must untrack this file with following command:
git rm --cache nasaAPU/Constrant.swift
An other way to ignore this file is to write two stars in front of it. Then you ignore every file with the name Constrant.swift in that repository. So you doesn‘t need to add the folder name where Constrant.swift is located before. But be careful with that:
**/Constrant.swift
After that, you can add (git add .
) your changes (edited .gitignore
and untrack the Constrant.swift file) and commit (git commit -m "No longer tracking Constrant.swift to include in gitignore"
) them.
Now, after git push
, Constrant.swift isn‘t longer available on the GitHub remote repository.