iTranslated by AI
I want a .gitignore for OneDrive
Even when using Git / GitHub, I think there is a demand to ultimately back up your work to cloud storage such as OneDrive. However, OneDrive does not explicitly provide a function to set files or folders to be excluded from synchronization. In this article, I will introduce methods to set files and folders to be excluded from synchronization in OneDrive. By using these methods, you can exclude unnecessary folders such as node_modules or .venv from synchronization, which may help save cloud storage capacity and solve problems where the sync status never completes.
1. Introduction
The methods I will introduce are as follows:
- Excluded file extensions
- Choose folders
odignore.txtClientPolicy.ini-
NucleusUpdateRingConfig.jsonandPreSignInSettingsConfig.json
2. Excluded file extensions
2.1. Procedure
The procedure is as follows:
- Open OneDrive Settings
- Select "Exclude" from
Sync and backup > Advanced settings > Excluded file extensions - Enter the file extension you want to exclude and click "Exclude"
2.2. Principle
This is simply using a feature built into OneDrive for its intended purpose.
2.3. Issues
The issues are as follows:
- Configuration is required for each client
- Folders cannot be excluded
- Files can only be excluded based on their file extension
- It doesn't work in the first place
I wonder why it fundamentally doesn't work. Also, please note that this does not apply to files that have already been backed up to OneDrive.
3. Choose folders
3.1. Procedure
The procedure is as follows:
- Move the contents of the folder you want to exclude from synchronization to another location
- Open OneDrive Settings
- Select "Choose folders" from
Account > Choose folders - Select the folder you want to exclude from synchronization and click "OK"
- Move the contents back to the original folder
3.2. Principle
OneDrive's "Choose folders" feature is originally intended to prevent folders on cloud storage from syncing to the local machine. By taking advantage of this, you can create a folder on the cloud storage in advance and exclude it from the local sync targets, thereby preventing local changes from being reflected in the cloud storage.
3.3. Issues
The issues are as follows:
- Configuration is required for each client
- The procedure is cumbersome
- Configuration is required for each project
- Appears as a "Sync issue"
4. odignore.txt
4.1. Procedure
The procedure is as follows:
- Open
C:\Users\%USERNAME%\AppData\Local\Microsoft\OneDrive\settings\Personal\odignore.txt - Describe the patterns of files/folders you want to exclude
4.2. Principle
Actually, this odignore.txt is a file generated by the "Excluded file extensions" setting. However, unlike setting it through the "Excluded file extensions" screen, you can write free patterns instead of just extensions. If you write patterns directly into odignore.txt, they will be reflected in the OneDrive settings screen as well. The UI descriptions also correspond correctly to the patterns, suggesting that the functionality is intended to be supported. In the future, it might become possible to write patterns directly from the OneDrive settings screen. Alternatively, it might be a feature for OneDrive for Business, where administrators can reportedly exclude files and folders.
4.3. Issues
The issues are as follows:
- Configuration is required for each client
- It doesn't work
Since "Excluded file extensions" is currently not working, folder exclusion is naturally not working either. However, since "Excluded file extensions" is a feature that has already been launched, it will likely be debugged soon. It would be great if the directly edited odignore.txt also becomes functional at that time.
5. ClientPolicy.ini
5.1. Procedure
The procedure is as follows:
- Open
C:\Users\%USERNAME\AppData\Local\Microsoft\OneDrive\settings\Personal\ClientPolicy.ini - Describe the folder names you want to exclude in
HighVisibilityFileExclusionList
5.2. Principle
ClientPolicy.ini is a file where various backend settings are written. There is an item called HighVisibilityFileExclusionList in this file, and by describing the folder names you want to exclude there, you can exclude them from synchronization targets. Taking a quick look at ClientPolicy.ini, it seems you can specify multiple items by separating them with |. Also, items starting with .. are likely a whitelist. There is a similar item called FilenameExclusionList. This one also showed similar behavior. The difference is not well understood.
5.3. Issues
The issues are as follows:
- Configuration is required for each client
- Appears as a "Sync issue"
- Configuration is required for each client
6. NucleusUpdateRingConfig.json and PreSignInSettingsConfig.json
6.1. Procedure
While looking at the directory containing OneDrive configuration files, I found other files that seemed relevant:
C:\Users\%USERNAME%\AppData\Local\Microsoft\OneDrive\ListSync\settings\NucleusUpdateRingConfig.jsonC:\Users\%USERNAME%\AppData\Local\Microsoft\OneDrive\settings\PreSignInSettingsConfig.json
Editing these properly might allow for the exclusion of files and folders.
6.2. Principle
OneDrive actually has a proper built-in function to exclude specific files from synchronization. This is because it correctly excludes system files such as:
- .laccdb
- *.tpm
- thumbs.db
- EhThumbs.db
- Desktop.ini
- .DS_Store
- Icon\r
- .lock
NucleusUpdateRingConfig.json and PreSignInSettingsConfig.json mentioned above are thought to be related to these settings. However, editing these files did not enable the exclusion of files or folders. As for PreSignInSettingsConfig.json, it appeared to be automatically overwritten whenever OneDrive was launched.
6.3. Issues
The issues are as follows:
- Configuration is required for each client
- It doesn't work
7. Summary
I have introduced methods for setting files and folders to be excluded from synchronization in OneDrive. In the end, it seems that the method using ClientPolicy.ini is the most practical among those that actually work. I have decided to exclude node_modules by adding it there.
As for the outlook, it would be great if "Excluded file extensions" started working properly. If it does, we might be able to exclude files and folders by directly editing odignore.txt. Furthermore, in the future, it would be ideal if we could configure settings using a file like .onedriveignore placed within the shared folder, similar to .gitignore. This would eliminate the need for per-client configuration. Ah, if only there were a cloud storage service that supported exclusion settings like .gitignore.
8. Epilogue
Originally, I wanted to exclude node_modules and .venv, but I was able to successfully exclude them by using the Dev Container Volume trick.
Discussion