ALWAYS UNDER DEVELOPMENT
ArcWeb / by Danny

Git: How to ignore files

You create a .gitignore file in repository root and edit the file.

here is an example of rules to ignore files from being added to repository:

# first line must not contain any rules

/*.gif

images/*
!images/gallery
images/gallery/*

logs/*
tmp/*

!.gitignore

- first line must not contain any rules because they will be ignored

- !.gitignore use it as last rule, “!” sign is used to tell Git the exceptions, so it means don’t ignore .gitignore files from current repository

- /*.gif ignores all gif files from repository root, if you want to ignore all gif from repository remove the slash (/)

- images/* ignores all files from images folder, but if you create  images/.gitignore (can be an empty file), then the images folder will be added for commit, because of the last rule the folder will not be empty (empty folders are not added)

- !images/gallery tells Git to add folder images/gallery (also has an empty .gitignore inside like images/*)

- images/gallery/* ignore all from gallery

- logs/* and tmp/* rules are like images/*, also they have a .gitignore and empty folders will be included in repository

- you can add rules in the empty .gitignore files; as example you remove  images/gallery/* rule from root .gitignore and in images/gallery/.gitignore you write *, or in images/.gitignore you write gallery/* and will have the same effect

 

You can use command git add -n . in Git Bash to test what files will be added to your repository.

 

Leave a Reply

Who is on a skateboard?

CuteCaptcha