Git Ignore
Add a File to .gitignore
NOTE: .gitignore ignores just files that weren’t tracked before (by git add). If You’ve already committed the file from Git you have to tell git to stop tracking it. View: Remove Files Already Committed to Git
Remove Files Already Committed to Git
If the file you wish to ignore from Git has already been committed to git you have to tell git yourself to stop tracking that file.
The problem is that .gitignore ignores just files that weren’t tracked before (by git add). Run git reset name_of_file to un-stage the file and keep it. In case you want to also remove given file from the repository (after pushing), use git rm –cached name_of_file.
Reference: StackOverflow: how-to-ignore-certain-files-in-git
Untrack files in git repository based on .gitignore
Untrack files already added to git repository based on .gitignore
-
Commit or stash all your changes.
-
Create a
.gitignore
file.
- Remove all files from local git.
$ git rm -r --cached .
rm
will remove files from the repository’s git (stop tracking specified files in git).-r
will allow recursive removal–cached
will only remove files from the git index. Your files will no tbe deleted from the directory.- The
.
indicates that all files in the current directory will be untracked. You can untrack a specific file with git rm--cached foo.txt
NOTE: “The rm command can be unforgiving. If you wish to try what it does beforehand, add the -n or –dry-run flag to test things out.”
- Re add all files in the directory to git. Since there’s a
.gitignore
file present, only files NOT specified the.gitignore
will be added back into git.
$ git add .
- View changes to the repository’s git.
$ git status
- Commit the changes.
$ git commit -m ".gitignore fix"
File Still Committing After Adding to .gitignore
git rm --cached .flutter-plugins-dependencies
Reference: how-to-put-flutter-plugins-dependencies-in-the-gitignore
Journal
- 2019.01.24 Created
Add a file to .gitignore
. This was a Google Doc I made - 2020.06.07 Created
Git-Ignore.md
. This was a Google Doc I made - 2020-10-22 Added
File Still Committing After Adding to .gitignore
section - 2021-04-03 Added
Untrack files in git repository based on .gitignore
section