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.
And we make another directory backup
which is the backuping folder for Google Drive.
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!
Some concerns:
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.