One good habit that team can do when building their project in a Git repository, is merging and rebasing as often as possible.
A good reason for this is that you’ll have much easier and manageable conflicts. Another reason is simplicity, in my experience the problems that people encounter with Git are often a result of their own choice towards complexity, i.e. complex branching hierarchies.
Keep things simple!
But I digress, the topic of this post is how to clean up .orig files that may occur and build-up in your project’s repository.
One command that you’ll find quite useful is
git clean, it removes untracked files from the working tree of your project. Most often you’ll use it like so:
git clean -fd
The reason for this is that
git cleanwon’t even run unless you give it the
-dwill also remove directories that not under version control.
Another useful argument is
-nwhich will do a dry-run and show you what would be removed:
git clean -nd
Configure your mergetool
You can also configure you mergetool to not preserve the .orig files, however not all Git mergetool’s support this feature and still preserve the .orig files even with this configuration:
git config --global mergetool.keepBackup false
Just ignore them!
Add this to your project’s .gitignore file:
This is the most simplest of all solutions and ultimately probably the best, if this what you choose to do the
git cleanwill still be able to clean them but you will have to invoke it with the
git clean -fdx
If you’re already ignoring a lot of files or have files ignored that you need for your Development environment e.g. tags, logs, or config files then you just need to stipulate the path you want cleaned so they aren’t removed:
git clean -fdx app