DEV Community


Remove committed file from a repository

Raul Montero
Senior mobile developer who enjoys in bringing ideas to life, from conception to the stores and behond.
Originally published at on ・1 min read

No matter what kind of project you are working on, they all have auto-generated files that don’t need to go inside the remote repository, but more often than not, we find ourselves working on projects that have those files already pushed and end up having to deal with conflicts that could have been avoided otherwise.

Thankfully, there is a way to remove those files and make sure no other developer commits them ever again.

1. Remove the file locally

git rm -r --cached route/to/file.cs

2. Prevent the file to be added ever again by adding it to the .gitignore definition.

  • Open the terminal and navigate to the root of your project folder
  • Enter open .gitignore to open the gitignore file in your default text editor. If you don’t have one you can find one configured for your specific project in
  • Add the relative path of the file you wish to ignore. Here’s a sample ignoring the AndroidResource.designer.cs of a xamarin project
# http://Xamarin.Android Resource.Designer.cs files


3. Stash changed files

git add route/to/file.cs && git add .gitignore

4. Commit changes

git commit -m "Removed auto-generated [file] from repository"

5. Push changes

git push origin master

Discussion (0)