-2

I want to do the opposite of this Remove a file from a Git repository without deleting it from the local filesystem

For example, I have a folder in my repositories root directory examples. I want this folder to be in the remote repo. However, in some local environments it is not needed. So I'm wondering if there is any way to git pull everything except examples?

Akkua
  • 101
  • 1
  • 7

2 Answers2

1

Git doesn't traffic in files. It doesn't traffic in folders. It doesn't traffic in changes. It traffics in commits. A commit is a complete snapshot of your entire project at the time the commit was created. When you pull, you pull a commit (although you will say it as the name of a branch).

Therefore, when you pull, you get all the files and all the folders that constituted the project at the moment that commit was created. That's just the way it is.

Now, if you don't like what that does to the contents of a certain folder, you can restore the older contents of that folder after the pull. But you can't prevent the pull from doing what pulls do.

Of course, if you delete the folder and check that deletion into a commit, then when someone pulls that commit, that folder won't be there. But again, that's because it wasn't part of the commit. It isn't because you did some sort of "partial pull" — there's no such thing.

As you've been told in a comment, the closest you can get to that sort of thing is a "sparse checkout", so you might like to research the possibilities in that regard.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

However, in some local environments it is not needed. So I'm wondering if there is any way to git pull everything except examples?

There isn't really a way to do exactly that with Git.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47