15

With git and hg, etc, you can define .gitignore file that will prevent certain folders/filetypes from being saved to the repo.

Is there anything of that nature for Google Drive? In the preferences, I see I can select a parent folder to not be synced, but I see nothing along the lines of subfolders.

Env is OS X...

1
3

The way I deal with this is to:

  1. Disable starting GoogleDrive on system startup
  2. Create a bash script to clear temporary and log files first, and then run google drive
  3. Schedule that script to start on system boot

I know its far from perfect, but its something.

4
  • 1
    I like it. It's not so far from perfect. – Sam Hammamy Dec 6 '14 at 23:10
  • Unfortunately, it's one of the better solutions I've seen since Google has yet to implement a feature that allows us to exclude particular filetypes, etc. My copy of Adobe InDesign will only allow me to save a file once because the .idlk file (lock file) becomes perpetually stuck trying to upload in Google Drive sync. – armadadrive Oct 1 '15 at 13:51
  • 2
    Not quite a solution. For developers, those "unwanting to sync" files are actually required for development. Like node_modules, .git files, and many others – scazzy Feb 8 '17 at 7:19
  • @EltonJain But still, IDEs like PHPStorm generate thousands of little files for each new project which, or even cache those settings ... all of this nonesense belongs in the local – samayo Feb 24 '17 at 13:35
3

For Windows, I use a simple Powershell script that relocates the desired folders (node_modules) to a different location outside Google Drive, and replaces them with Symbolic links so everything keeps working.

It can be found in this repo, along with the instructions to set it up.

2

Symbolic links could be used in this case. Google Drive doesn't seem to detect symbolic links, so you can put your node_modules somewhere outside the Drive, then inside the drive create a symbolic link to node_modules.

Example structure:

google_drive
    my_app
        package.json      file
        app.js            file
        my_apps_stuff     folder
        node_modules      symbolic link ==> /home/me/gdrive_ignored/my_app/node_modules

Linux, Windows, and OSX all have symbolic links.

If you run into issues with your application not working with symbolic links, then create a hard link.

2
  • This seems like a better solution. What about when you deploy that file, you have to do npm install again right? – samayo Jul 9 '19 at 17:56
  • Yes. The modules should not be bundled with the software when deploying. – Jack Cole Jul 9 '19 at 18:57
1

This problem bothers me for years and I recently found a better way to deal with it.

The main idea is to use ".gitignore like" option to backup the files.

So just use .gitignore directly by the powerful version control tool: git

My OS is Windows 10. I perform the following commands under Windows Subsystem for Linux.

Assume that there are many repositories under local/codes. Each of them has remote connected to Github etc. or not.

Like the following structure:

local/
└── codes/
    ├── repo_1/
    │   ├── .git/
    │   ├── .gitignore
    │   └── .../
    ⋮
    └── repo_i/
        ├── .git/
        ├── .gitignore
        └── .../

Despite using Github to remote backup is convenient, the goal is to backup in Google Drive.

  • Step 1: setup local

    git init

    cd codes/

    git submodule add <repo_1_URL>

    git submodule add <repo_i_URL>

    cd ..

    git add -A

    git commit -m "first commit"

And we make another directory backup which is the backuping folder for Google Drive.

backup/
local/

cd ../

mkdir backup

cd backup

  • Step 2: setup backup

    git init

    git remote add origin ../local/.git/

    git pull origin master

    git submodule update --init --recursive

For more details about submodule update, you can refer to this link.

The magic here is that we set the remote local/.git in backup so that it will be a "remote" repository for backup. After that, all git pull will follow all .gitignore recursively under all directories!

So now the backup folder is like:

backup/
├── .git/
├── .gitmodules
└── codes/
    ├── repo_1/
    │   ├── .git
    │   ├── .gitignore
    │   └── .../
    ⋮
    └── repo_i/
        ├── .git
        ├── .gitignore
        └── .../

without any files specified in .gitignore. Just like a local Github!

  • Step 3: Setting Google Backup and Sync on the folder: "backup/codes"

  • Step 4: Keep updating files...

    • local

      git submodule update --recursive --remote

      git add -A

      git commit -m "commit message"

    • backup

      git pull origin master

      git submodule update --recursive

Some concerns:

  1. Duplicate files?

    Yes! It's a feature not a bug.

    Since for each Github repository, the maximum storage size is 100 MB. So the total disk usage should not be large after filtered by .gitignore.

    To backup is to copy files on different devices. By making backup folder in another hard drive, we can now backup files to different hardware, to Google drive and to Github simultaneously!!


This idea ​comes from learning more features in git.

I watch the Missing Semester Version Control (Git).

Anish introduces very clearly and I learn a lot about git. In the part that he creates local git remote makes me come up with this idea.

New contributor
Pei-Ying Liu is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.