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

  • How to show git author name in Sublime Text editor?
  • How to commit specific file in index?
  • Does Mercurial have an equivalent to git clean?
  • Already uptodate in git - GIT PULL works but not GIT FETCH
  • How do I save work in progress without using git-stash?
  • In GitHub, at what levels can review comments be made?
  • /folder/another/file.txt
    /folder/another/~file.txt
    

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

  • GIT_DISCOVERY_ACROSS_FILESYSTEM problem when working with terminal and MacFusion
  • Stashing changes during an incomplete merge
  • Handling file renames in git
  • In gitk, why is my yellow button above master?
  • How do I undo this git configuration?
  • How can I clone a non-github hosted repository using Github Desktop
  • 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.