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.
git rm -r --cached route/to/file.cs
- Open the terminal and navigate to the root of your project folder
open .gitignoreto 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 gitignore.io.
- 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 **/*.Android/**/[Rr]esource.[Dd]esigner.cs **/*.Droid/**/[Rr]esource.[Dd]esigner.cs **/Android/**/[Rr]esource.[Dd]esigner.cs **/Droid/**/[Rr]esource.[Dd]esigner.cs
git add route/to/file.cs && git add .gitignore
git commit -m "Removed auto-generated [file] from repository"
git push origin master