Ignoring Files That Are Already in a Git Repository

March 5th, 2018

Filed under: Version Control, Xcode | Be the first to comment!

In a previous post, I showed how to tell git to ignore files in Xcode projects. But what do you do if you want to ignore a file that git is currently tracking?

Remove the file from the git repository. Add the file you want to ignore to the git ignore file. If you don’t perform this step, git will track the file when you add it back to the repository. Add the file back to the project after removing the file from the repository.

Removing a File That’s in an Xcode Project from the Repository

To remove a file that’s part of an Xcode project from a git repository, you must remove the file from the project. Select the file from the project navigator on the left side of the project window and press the Delete key.

Xcode will ask you if you want to remove the reference to the file from the project or move the file to the Trash. Move the file to the Trash.

After removing the file from the project, choose Source Control > Commit to commit and remove the file from the repository.


Add the File back to the Project

Now that you removed the file from the repository, get the file out of the Trash and move it back to your project folder. Choose File > Add Files to ProjectName to add the file back to your Xcode project.

Tired of Losing Work?

Have you ever saved a source code file and wished you could go back to the way it was before you saved? Have you ever accidentally deleted files from an Xcode project? Have you ever lost work due to Xcode crashing? If you answered Yes to any of these questions, I can help you.

I’m writing a book, Version Control for iOS and Mac Developers. As the title indicates, it’s a book about version control for iOS and Mac developers. In the book you’ll learn how to place your Xcode projects under version control to minimize the chances of you losing important work. You’ll also learn how to put your projects on GitHub and Bitbucket so you can easily work on projects with other people and create branches so you can build new features without breaking working code. The book also contains exercises for working with version control so you can practice using version control before using it in your own projects.

Sign up for my newsletter to get version control tips, access sneak peeks from the book, and get the chance to buy the book at a discount when it’s finished.

I want to learn more about version control



Leave a Reply

Your email address will not be published. Required fields are marked *