user1692342
user1692342

Reputation: 5237

Avoid pulling files which are in .gitignore

I have git repository and I am collaborating with other developers. I have written added folders in my .gitignore file to ignore them.

However whenever I do git add . , it adds the files from these folders. Also when I pull the latest code from, using git pull it fetches the files from the folders listed in gitignore. Is there a way to avoid getting the latest changes for the files mentioned in .gitignore?

My .gitignore file is as shown below:

/log/*
!/log/.keep
/tmp
/db
/bin
/lib
/public
/test
/vendor
/.idea/*
.idea/

Upvotes: 1

Views: 85

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 96934

gitignore is only for ignoring untracked files, whereas your files are already tracked in the index, so gitignore has no effect. What you want instead is to use git update-index --skip-worktree option:

Skip-worktree bit can be defined in one (long) sentence: When reading an entry, if it is marked as skip-worktree, then Git pretends its working directory version is up to date and read the index version instead.

Pass file(s) as additional arguments to mark them as skip-worktree, e.g. git update-index --skip-worktree file-a.txt file-b.txt.

Upvotes: 2

Related Questions