Home > Net >  Git - pull file only if not already present
Git - pull file only if not already present

Time:07-14

I have a project in my repo and it contains 3 sqlite database files. When I pull the repo on a pc, I need to download those files to in order for the program to work.

But once the files are present locally, I do not want to overwrite them on new pulls. Is there a way to ignore those files only if they already exist? And is there a simple way to force the pull anyway in case of big structural changes?

CodePudding user response:

I think git pull --autostash might be an option for you.

It stashes the existing changes before pulling applies the stash after pulling, therefore the files are not overwritten by the pull.

For more information see the git pull options

Note: This does NOT ignore the files while pulling, but the "dirty" files should not be changed by the pull.

CodePudding user response:

The "right" Git answer here is simply "don't do that". It's not very satisfying, but it's the only right answer.

You can use various tricks to attempt what you're doing, but in the end, none of them will work for every case. What will work for every case is to not have these files in any commit. If a template is required, have a template file (in every commit), and use some installation process to copy the template file into place. (That may be as trivial as make install-databases or cp template.sql db.sql or whatever; you can also set up your software so that when run, if the database isn't there, it's created from the template.)

It's not immediately obvious, but this is in fact a Git Frequently Asked Question:

How do I tell Git to ignore tracked files?

A common reason to ask this question are configuration files which are added to a project as an example or default, but which individual developers may want to change. Keeping uncommitted changes around is undesirable in the long run ...

  • Related