How do I tell git to ignore files that start with a tilde?

My text editor creates swap files that start with a tilde. I accidentally checked on of these into git. How do I tell git to ignore any files like this anywhere in my project tree?

So I had

  • git ls-files: howto identify new files (added, not committed)?
  • Gitolite and non-bare repos?
  • Why isn't the git stash unique per branch?
  • Git branches behaving strangely
  • Is there a way to re-order Git stashes?
  • Installing Git on CentOs
  • /folder/another/file.txt

    I want ~file.txt to be ignored by git.

  • Fix history after forced push
  • Am I looking at GIT branches in GIT clients wrong?
  • Heroku Cannot GET /
  • Git checkout <latest branch you were working on> command
  • How to delete files from git bare remote repository?
  • How to specify git email address on the command line?
  • 2 Solutions collect form web for “How do I tell git to ignore files that start with a tilde?”

    Just use a .gitignore file:

    echo '~*' >> .gitignore

    Alternatively, you can also write this line to .git/info/exclude which is a project-wide local ignore file (which you obviously cannot check in, as you can do with .gitignore).

    echo '~*' >> .gitignore

    This will append the needed entry.

    Else edit the .gitignore file manually and add ~* on a new line.

    Git Baby is a git and github fan, let's start git clone.