How to keep git from tracking all files that end with a "~"?

gitignore is the way to go. Just add *~ to .gitignore at the root of you repo.


You want a gitignore file.

If you want to nuke everything that ends with a tilde (which should be safe; I can't imagine a reasonable use-case where that's bad), make sure the following line is in your .gitignore file at the top of your repo's folder hierarchy:

*~

If you also want to get rid of those tilde files laying around in your local file system, you can. It'd be best to make Gedit put its backup files somewhere else. JEdit and VIm, the two editors I use most, have such settings, and it's lots cleaner to keep those somewhere else than loading up gitignore.

Unfortunately, Gedit doesn't have that option. The best it can do is to turn off the ~ backups. Before you get worried, the worst case is that you lose what was in the file immediately before you saved. That's not a worst-case -- that's why you've got this in a git repo, right?

NOTE: If you want to keep the ~ suffixed files locally, do. The .gitignore you set up, above, will keep you from accidentally sharing them.

You can turn off ~ suffixed backups like this

To prevent Gedit from creating these backups in the future, open up Gedit, open up the Preferences dialog (Edit > Preferences), select the Editor tab, remove the check in the “Create a backup copy of files before saving” option, and click Close. After doing this, Gedit will no longer make the backups with tildes all over the place.


To add on to what @filmor said, you can create a global gitignore file so that all repositories will ignore the backup files:

git config --global core.excludesfile ~/.gitignore_global

This will tell git to look in your $HOME path for a .gitignore_global file, which is where you can place the *~ rule.


Just complementing the answers:
If you have tilde files with extension, like Sketchup, which creates backup files ending with "~.skp", then you need to add *~.skp in your .gitignore file. Or change skp for the extension of the software you are using. Or use *~.* if you are sure that all files ending with tilde with all extensions are safely to be ignored.