Google Drive with a .gitignore like option

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...


Solution 1:

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.

Solution 2:

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.

Solution 3:

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.

Solution 4:

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 in local
    git init
    cd codes
    git submodule add <path_to_repo_1>
    ⋮
    git submodule add <path_to_repo_i>
    cd ..
    git add -A
    git commit -m "first commit"
    

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

  • Step 2: setup backup in backup
    git init
    git remote add origin <path_to_local>
    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 <path_to_local> 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...

    • in local
      git submodule update --recursive --remote
      git add -A
      git commit -m "commit message"
      
    • in 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.