Monday, 2 October 2017

How to exclude files from git using gitignore

During the development phase of the software in addition to the sources there are files that you want to exclude from git as binary files, eclipse settings files etc...
All these files should not be edited, so we can exclude them through a suitable configuration.

Create a local .gitignore 

A soluntion a this issue is the creation of a file with name ".gitignore" in main directory of your repositoriy.

Example

An example of gitignore file is the following:
# Compiled source #
###################
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
*.7z
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs #
########
*.log

# OS generated files #
######################
.DS_Store*
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Refresh cache about gitignore

If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
 git rm --cached <FILENAME>

Create a global .gitingore

Alternatively you can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repository on your computer. For example create a file like local .gitignore in home with name ".gitignore_global" and run the following command into your shell:
 git config --global core.excludesfile ~/.gitignore_global

No comments:

Post a Comment

Welcome

Hello everybody, Welcome in my blog called "Information technology archive". Obviously the topics will be related to Informatio...