.gitignore not ignoring Library. What's the correct way to do it?

First time Version Controlling, I’m using Bitbucket and SourceTree on Windows.

I created a new project, cloned it as a new repository, committed the changes. Then, I tried to gitignore the “Library” folder (since I’ve read I should) by using this:

Here’s where I think I did something wrong:

I went to the project folder [User/Documents/MyProject] and created a text document named “.gitignore” with the content above. Having done that, I went back to SourceTree and committed the change.

Now, by doing that, should I expect the metadata files to get ignored? because they didn’t. Actually, it had no effect on the repository. I tried different versions of “.gitignore” but all handed the same results. So my question is:

TL;DR: What is the correct way to .gitignore?

Problem: .gitignore has no effect.

Reason: Its extension is “.txt” → [.gitignore.txt]

Solution: Change it to “.gitignore” → so it can become just [.gitignore]

This can be achieved in 3 simple steps:

  • Open your project folder [User/Documents/MyProject]
  • Hold SHIFT, right click anywhere in the folder you’re in, then select Open command window here
  • Then rename the file in the command line, with: ren gitignore.txt .gitignore

Thanks to @BonfireBoy and @saschandroid