• Home
  • Git
  • Programming
  • Leadership
  • About

Git Fetch Victor

Git, Programming and so much more...

Git rid of unwanted files…

Written by vjpudelski on March 11, 2016

In working with the apprentices that I work with a common issues is forgetting to add a .gitignore file when you initially setup the repository. This can suck in the long run as many files that you don’t want to track start showing up in your repository and worse yet in merge conflicts with other users. A great example of this is the files within the target/ folder in NetBeans (Java) or for my .NET, Visual Studio folks, the files within the bin/ directory. In either case these are the files that are getting built by the code that we wrote and we only want the code in the repository not the assemblies and jars, right… So how do we fix the mistake once it has already happened?…

To fix this issue you want to start by getting the .gitignore file in the repository pronto. To do this, why create it from scratch… instead here is a link to a github repo with many .gitignore files already created and ready for you copying pleasure.

github link

Find the .gitignore file that you need and add it to the repository but don’t commit just yet.

With the .gitignore file in play start running git rm to get rid of the unwanted files.

Example: git rm -rf MyProject/bin/

the git rm is to remove the files from the repository
-r will recursively traverse the directory for any subfolders
-f forces the files out
MyProject/bin/ is the directory to remove, this can also be a single file as well.

Now once you run this command you will see the files marked as deleted but they should not now nor ever show back up to be added to the repository with the .gitignore properly in the repository. Thus, it is safe to remove the files and forget they were ever part of the repo.

Special Note: in working in teams, make sure other members of the team pull your changes after deleting such files. If they don’t know to look for the deletions they may accidentally override your changes and all the files back. A good practice here would be to get everyone on the same commit, remove the files and then have everyone pull the new commit without the files and continue working.

Posted In Git
Tagged git

Post navigation

PreviousProductivity Weekly Review
NextManaging Stress

Leave a Reply Cancel reply

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

Recent Posts

  • Leaders Eat Last
  • Java calling .NET WebAPI
  • So What Really Mattered?
  • What really matters?
  • Has It Really Been Over a Year!

Recent Comments

  • Jason King on Has It Really Been Over a Year!
  • Sarah Dutkiewicz on Changing the Past
  • Dave Balzer on Team Culture
  • Sarah Dutkiewicz on Team Culture
  • Sarah Dutkiewicz on Impostor Syndrome, my dealings…

Archives

  • April 2019
  • February 2019
  • January 2018
  • October 2017
  • September 2016
  • August 2016
  • July 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • August 2015
  • January 2015

Categories

  • Git
  • Leadership
  • Non-Technical
  • Personal
  • Programming
  • Raspberry Pi
  • Reviews
  • Troubleshooting
  • Unstoppable Course

Tags

aspnet aspnetcore books coaching CodeMagazine cron csharp culture dotnet dotnetcore dreams git iPhone java management nike Nozbe Raspian rsync running samba server source control SubtleArtOfNotGivingAFck teams vscode web hosting

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025. Git Fetch Victor
Powered By WordPress and Auspicious