Search code examples
gitfilebackup

Solution to store specific files not ignored on .gitignore


My problem is that I often forget to backup or I need to use some ignored files in other devices, like .env ones, and sometimes it troubles my day because those files should not be commited, but at the same time I need those files updated if for some reason I need to use this repo in another device.

Is there any solution for that when I commit to my repo, some selected files can stored in a clould service like onedrive or google drive?

I tried to use my repos inside a folder that is synced with my clould, but the amount of files not ignored, like venv or node_modules, more hinders than helps me.

Thank you!


Solution

  • If you are specifically targeting ignroed files :

    you can list the ignored files in your directory using :

    git ls-files --exclude-standard -i -o
    

    You can then use the output of this command to do something with the listed files.

    For example, you can create a tgz archive :

    # create a tgz archive :
    git ls-files --exclude-standard -i -o | xargs tar -czf ../myenvfiles.tgz
    

    and copy/extract that archive some place else.