How to hide files to Git.
- Gitignore : Complete description and syntax for the
.gitignore
file - Gitattributes : Informations about Git treatment on commit, not describe here
Assuming:
- Commands are executed on an UNIX System
$PROJECT_PATH
is the root of the project- The project is a Git one (
ls $PROJECT_PATH/.git
)
Create a .gitignore
file in $PROJECT_PATH
then list the excluded paths
Note: .gitignore
file can be nested and will be applied only on subfolders (relatively)
This .gitignore
is named exclude
and located at: $PROJECT_PATH/.git/info/exclude
This file will not appear in git status
, it's a ghost.
This Gitignore file should be defined in the global git config located at ~/.gitconfig
(maybe empty)
Retrieve the Gitignore file: git config --global core.excludesfile
Define the Gitignore file: git config --global core.excludesfile ~/.gitignore
(path and name of ~/.gitignore
is editable)
Note: Syntax of .gitconfig
file
# [core]
# excludesfile = /path/to/user/home/.gitignore
git rm fileToIgnore.cobol
- Add
fileToIgnore.cobol
to.gitignore
- Commit / Push
If the file is still here (in staged changes): git rm --cached fileToIgnore.cobol