0

How can I configure git, so that node_modules can be versioned locally but ignored when pushing? Is there a possibility?

Why: Different packaging systems (e.g. npm/yarn/..) access node_modules and sometimes some packages get corrupted. We want to monitor, what the tools change exactly. And node_modules should not be pushed onto the development server.

Aurora0001
  • 13,139
  • 5
  • 50
  • 53
  • You can't, so use Vampire's technique (multiple Git repositories). – torek Dec 01 '16 at 17:16
  • The creators of git didn't think about such of possibility? –  Dec 01 '16 at 17:23
  • Git is explicitly designed so that you *cannot* prevent anyone with the repository from doing whatever they want with the repository. Files within the repository are not stored by path name but rather by "object ID" (hash ID), and pushes are not done by file, but rather by *commit*. You either have a commit (and then you have all of it), or you don't (and then you have none of it). There are some ways to get only some, rather than all, commits, but they are tricky to use. – torek Dec 01 '16 at 18:03
  • 1
    Dear torek, to my mind it is a necessary feature and it is forgotten. .gitignore_local and .gitignore_remote would make sense. I'don't want to get e.g. node_modules from remote, these are data, which is generated locally. But in some circumstances I would like to know, what changes at the local side, i.e. the data is less important, I cant generate it from data, that I get from remote, but I'am interested in local changes. –  Dec 01 '16 at 18:41
  • Please take care when selecting tags and read the tag descriptions - [yarn] is not for the Yarn package manager and there is a "Do not use" notice there to remind you. I've edited the tags for you though, but be careful because some tags are a bit unclear. – Aurora0001 Dec 02 '16 at 16:40

2 Answers2

1

It is not possible.

What you can do is exclude node_modules from the Git repository and create a new Git repository within node_modules

tehp
  • 5,018
  • 1
  • 24
  • 31
Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Thank you, I currently do it at this way, but this a dirty trick and not a proper configuration,.. –  Dec 01 '16 at 17:19
  • Even if it is a dirty trick, it is the only possible solution. Either something is tracked by git or not. You cannot "partly push" only a subtree of your repository. This is simply technically impossible with Git. – Vampire Dec 01 '16 at 17:28
  • OK, I see, the correct answer would be: No, it is not possible, not yet. –  Dec 01 '16 at 17:47
  • 1
    That's exactly what I said. And it will never be possible. The complete file tree is part of the calculated hash value. – Vampire Dec 01 '16 at 20:17
0

You can define the following structure:

/project
/my_node_modules
Community
  • 1
  • 1
Ivan
  • 3,084
  • 4
  • 21
  • 22
  • Thank you, I currently do it something like that, but this a dirty trick and not a proper configuration,.. –  Dec 01 '16 at 17:20