Learn Courses My Dashboard

Question about gitignore

I am having a hard time to study how to use gitignore

For the case to create a brand new Xcode project, and create a gitignore file to ignore unwanted file like the GoogleService-Info.plist , I succeed to do so

But for the case when a Xcode project has already been pushed to GitHub, and it contains a unwanted file that I want to ignore, I don’t know what to do

My failed steps are:

  1. Delete unwanted file from GitHub repo
  2. Create a gitignore file in the existing local Xcode project file, add unwanted file name into it, push

And the result is:
-The deletion in GitHub repo becomes a commit. In a result, other users can go back to the early commits and still see the deleted file.
-The gitignore doesn’t work, may be because the unwanted file has already added to a “push list”??

And then I tried to create a new repo on GitHub, at the same time using gitignore to ignore the unwanted file in the same local Xcode project, and push to the new GitHub repo.
Then I found that the unwanted file is still there, and the new GitHub repo contains all the early commits

At last I have to start form stretch, create a new Xcode project, manually copy code to the new project, and add gitignore before I init a git, and its works finally

Is there a cleverer way to remove and ignore a unwanted file from a already pushed GitHub repo?


It works, but yes the issue is because you’ve already pushed the file.

A gitignore should be one of the first things you create when making a new Xcode project, cause like you’ve found out, once something is in git and has been committed, removing it is difficult

A gitignore will ignore (not commit) any files or directories (folders) that you specify

To fix this: you should have deleted the .git folder in your project. This is because your code is committed locally (on your computer) and in the remote (GitHub)

So he’s making a new GitHub repo can fix it, but you have to also delete the local git repo and make a new one. [Note]: doing this you will lose all your commit history!! If this doesn’t matter that’s fine.

See steps above, but yes doing this you made a new local repo.

The way I suggest above is best if you’re on a small project and it just happened.

But removing a file that’s already been committing can be very difficult, here’s some solutions

I believe it might always be in commit history, unless you remove that commit (which is a whole different thing, and also can be very confusing)

1 Like

Thank you very much!

I know what’s went wrong and what is the correct way to do now!

Can’t thanks more

1 Like