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.

GtiHub_add_file_to_gitignore_0

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

  1. Commit or stash all your changes.

  2. Create a .gitignore file.

  1. Remove all files from local git.
  $ git rm -r --cached .

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.”

  1. 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 .
  1. View changes to the repository’s git.
$ git status
  1. 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