0

Trying to understand how .gitignore files work: do they just ignore files only when you push to a branch or do they also ignore the same files if they've been updated on master, and you want to pull those changes? I know it works in one direction: when I want to push to a remote branch, and I'm wondering if it works in the reverse direction: when I want to pull changes for a gitignore-d file from a remote branch.

  • 1
    So many duplicates and refs elsewhere https://stackoverflow.com/q/3001888/1531971 https://stackoverflow.com/q/11451535/1531971 https://help.github.com/articles/ignoring-files/ (Show what research you've done and then re-ask in the context of all the reference material available to you.) –  Nov 19 '18 at 17:23

1 Answers1

2

That's not how .gitignore works. The only job of the .gitignore file is to prevent you from adding them to the staging area. Thus, if you try to

git add file.txt

and file.txt is mentioned in the .gitignore file, you will get an error:

The following paths are ignored by one of your .gitignore files:
file.txt
Use -f if you really want to add them.

You can use the -f flag, as mentioned in the error message, to add the file anyways:

git add -f file.txt

This also implies that files that are already tracked by Git are not influenced by the .gitignore file anymore. More on that here: How to make Git "forget" about a file that was tracked but is now in .gitignore?

alfunx
  • 3,080
  • 1
  • 12
  • 23