1

Is there any way to fetch a remote git repo while including the files ignored by git? Optimally including the .gitignore files themselves

So if I want to grab all the files from a remote application repository, even those not in the git repository because they are on the .gitignore file - only way to really do this is download files with ftp or something and attach the remote repo aftwards?

A_funs
  • 1,228
  • 2
  • 19
  • 31

2 Answers2

7

Files that have never been added to the repository, because they are ignored by git, can't be retrieved from the remote repository, because, well, they are not there in the first place.

Files that have been ignored after they have been added or that have been force added are in the repository just like any other file and will be fetched without any special action. The same is true for .gitignore files.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • 1
    files being ignored has almost no bearing on whether they are in a repository - it only means they were either added before the .gitignore rule existed or were force added e.g. https://gist.github.com/AD7six/8e13a511472ce9b2ab40 – AD7six Sep 16 '13 at 14:14
  • sweet - incidentally I updated the gist that had a bad copy/paste in it. – AD7six Sep 16 '13 at 14:26
  • 1
    @AD7six: Thanks. I would like to keep our comments because I believe they give some deeper insight into that topic. – Daniel Hilgarth Sep 16 '13 at 14:28
4

.gitignore files do not affect git fetch/git pull

A .gitignore file has no effect on remote git operations; it is only relevant when adding files to commit them (and also has no effect on already-tracked files).

As such, to receive all files (including files that are in the repository but now ignored) - the only thing that's required to do is fetch/pull as you would ordinarily do. If the .gitignore files have been added to the repository, they will be received as with any other file in the repository.

Files aren't in the git repo?

If there are files that are in a checkout somewhere, but aren't in the git repository that you wish to receive, they need to either be checked in, or downloaded directly. To add files that are ignored you'll need to use the --force flag:

$ cd /my/app
$ git add somefiles/
The following paths are ignored by onhe of your .gitignore files:
somefiles
Use -f if you really want to add them
fatal: no files added
$

Note specifically Use -f if you really want to add them. It's not impossible (or even difficult) to add ignored files to a repository, it simply requires you to confirm it's really what you want to do:

$ git add -f somefiles/
$ git commit -m "adding some files"
[master 98380d5] adding some files
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 somefiles/empty
Community
  • 1
  • 1
AD7six
  • 63,116
  • 12
  • 91
  • 123
  • -1: Just as misleading as you find my answer. Files that are ignored by `.gitignore` and because of this have never been added to the repository can't be fetched from a remote repo, because they are not there. Your answer sounds as if that is not the case. *"to receive all files including files that are ignored"* -> You can't get all files that are ignored. Only those that have been ignored after they have been added to the repository. – Daniel Hilgarth Sep 16 '13 at 14:13
  • 1
    see my comment on your answer (thanks for giving a reason for the down vote) - and/or read the help when you try and add something that's ignored. It's quite a common practice to have ignored files in a repository e.g. [these files](https://github.com/cakephp/cakephp/tree/master/app/tmp) [are ignored](https://github.com/cakephp/cakephp/blob/master/.gitignore#L4) – AD7six Sep 16 '13 at 14:15
  • Doesn't change anything. You can only ever get files that are in the repo. And because a .gitignore file is *usually* used to *prevent* files from being added to the repository, your answer describes merely a corner case, but not the normal case. – Daniel Hilgarth Sep 16 '13 at 14:16
  • it changes everything =) but you're welcome to think it's a corner case and/or take offense that I tried to point out the error in your answer. – AD7six Sep 16 '13 at 14:17
  • I think there is no error in either answer, and as such I offer to remove my downvote if you would edit your answer (it's locked in right now). It's just different point of views / usage scenarios, depending on where you are coming from. And I didn't take offense by your downvote. Just by your first comment on my answer. – Daniel Hilgarth Sep 16 '13 at 14:19