Skip to content

Instantly share code, notes, and snippets.

@HollyPony
Last active August 6, 2017 22:41
Show Gist options
  • Save HollyPony/e6f0ee02246893834cd18c56b8d86522 to your computer and use it in GitHub Desktop.
Save HollyPony/e6f0ee02246893834cd18c56b8d86522 to your computer and use it in GitHub Desktop.

Git ignore

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)

Ignore files project

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)

Ignore files project only for the user

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.

Ignore files for all user project (git --global way)

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

Ignore a file already commit / push

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment