how to gitignore a file code example

Example 1: create gitignore

# creates gitignore file
$ touch .gitignore

Example 2: How to ignore files in git

Then in Git Bash you have to write the following line:

git config --global core.excludesfile ~/.gitignore_global
--------------------------------------------------------------------
If the repository already exists then you have to do the following:

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
If the step 2 doesn’t work then you should write the whole route of the files that you would like to add.

Example 3: how to use gitignore to ignore a folder

You can ignore entire directories, just by including their paths and putting a / on the end:

1
2
node_modules/
logs/

Example 4: how to put files into gitignore

$ echo debug.log >> .gitignore
$ git rm --cached debug.log
rm 'debug.log'
$ git commit -m "Start ignoring debug.log"

Example 5: what to add to gitignore

Look at this awesome site!
https://www.toptal.com/developers/gitignore
Generates a gitignore for you, based on the technologies you're using

Example 6: how to git ignore a file

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