I have an unusual question for a git users:
I want to be a members of a git project which means that I want to be able to pull and push code to/from the repository while maintaining my own version of few files of the project which should not be pushed or pulled to the repository.
My ideal scenario would be one where when I push on git, I upload anything I have changed but not few predefined files, and when I pull, I download everything which is changed but not the just mentioned files.
I googled around finding that ".git/info/exclude" might help me, but I did not manage to make it work as I intended. So far, the only way I found that seemed to do what I intended, is use "git update-index --assume-unchanged ", but in order to do so, I must issue the command each time I push or pull anything to the repository.
Is there any cleverer way to accomplish this?

- 598
- 1
- 7
- 18
-
1Maybe you want something like this: https://stackoverflow.com/questions/1753070/how-do-i-configure-git-to-ignore-some-files-locally – gi097 Jul 20 '18 at 15:10
-
Possible duplicate of [How do I configure git to ignore some files locally?](https://stackoverflow.com/questions/1753070/how-do-i-configure-git-to-ignore-some-files-locally) – phd Jul 20 '18 at 15:38
1 Answers
In git, the basic unit that is pushed or pulled is the COMMIT
, which is a snapshot of the entire content at a particular time. File versions may be pushed as part of a commit, but unlike some older systems (e.g. cvs) which were a collection of versioned files, git has a versioned collection of files.
And commits are immutable. Every detail of a commit's content is an integral part of the commit's identity. So when you say anything about "this commit, but with one file (or a few files) different", that means "a different commit that's mostly similar to this commit".
And once you're talking about different sets of commits, you're talking about diverging histories.
I often see people recommend using index flags (like assume-unchanged
), but that's not what they're meant for. You've already observed that it doesn't work smoothly, and if you say "oh, well, there's nothing better" and do it anyway, it may lead to more hassles down the road.
If you need to have local differences, the best thing is to keep them outside your git work tree. (An alternative would be to keep them at ignored paths in the work tree, but since you don't fully control the upstream repo it may not be safe to assume a given path will always be unused.)
How to do that and still have everything work depends on your situation. Maybe you could use locally-modified build tooling (or other scripting) to insert your changes into local builds. You might be able to use .gitattributes
to set up a custom filter that swaps between your local version and the "canonical" version when moving the files between the index and the work tree (though I expect that to be tricky and possibly brittle).

- 42,148
- 4
- 35
- 52