Reputation: 1236
How do i exclude environment files from github for angular 4 project.
I have updated my .gitignore to the following, but my environment files are still being synchronised to github: /src/environments/**
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
testem.log
/typings
/src/environments/**
# e2e
/e2e/*.js
/e2e/*.map
# System Files
.DS_Store
Thumbs.db
Upvotes: 21
Views: 14318
Reputation: 35817
The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.
In other words, gitignore won't remove files that are already in your repository, it'll just stop them being added in the first place. So if you've already accidentally commited your environment files, adding them to gitignore isn't enough; you'll also need to untrack the files.
The documentation goes on to say how to fix it:
To stop tracking a file that is currently tracked, use git rm --cached.
Note that this won't remove the file from your commit history, however - if you've accidentally leaked any sensitive info, see the GitHub documentation for info on what to do.
Upvotes: 22