Using iCloud Drive to share git repo project
本帖最後由 javacomhk 於 2025-7-27 03:49 編輯
雖然呢的方法並不推薦not recommended,但作為一個私人分享的 shared repo 也是一個簡單易用的方案,唔使註冊 github 亦唔使整的 key。
分享 icloud 可以使用 Apple ID email 或 With Link
當您透過 iCloud Drive 共用檔案或資料夾時,其佔用的儲存空間將從發起共用者的 iCloud 儲存空間中扣除。
受邀查看或編輯共享內容的使用者的 iCloud 儲存空間不會受到共用檔案的影響。
Using iCloud Drive to share a Git repository with others is not recommended and is almost certain to lead to repository corruption and data loss. Standard Git hosting services are the correct and safe way to collaborate.
If you understand the risks and still wish to proceed, here is how it can be done.
-----
How It Works
You will create a bare repository inside a shared iCloud Drive folder. A bare repository acts as a central server but contains no working files itself. Both you and your family member will interact with this central repository via its local file path on your respective Macs.
-----
Step-by-Step Guide
I) Owner: Create and Share the Repo
1. Create & Share the Folder: In Finder, open your iCloud Drive, create a new folder (e.g., `SharedProject`), right-click it, select Share Folder, and invite your family member, ensuring their permission is set to "Can make changes."
2. Create the Bare Repo: Open the Terminal app. Navigate into your new shared folder and create the bare repository. It's conventional to name it with a `.git` suffix.
```bash- cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/SharedProject
- mkdir my-repo.git
- cd my-repo.git
- git init --bare
- touch git-daemon-export-ok
複製代碼 ```
3. Push Your Existing Project: If you have an existing project, navigate to it in the Terminal and add the shared repo as a remote.
```bash- # Navigate to your project folder
- cd ~/path/to/my-project
- # Add the remote
- git remote add icloud ~/Library/Mobile\ Documents/com~apple~CloudDocs/SharedProject/my-repo.git
- # Push your code
- git push icloud main
複製代碼 4. Wait for iCloud to completely sync all changes.
II) Collaborator: Clone the Repo
1. Accept the Share: Your family member must first accept the iCloud sharing invitation. The `SharedProject` folder will then appear in their iCloud Drive.
2. Clone the Repository: On their Mac, they should open Terminal and clone the repository using its local file path.
```bash- git clone ~/Library/Mobile\ Documents/com~apple~CloudDocs/SharedProject/my-repo.git
複製代碼 ```
3. They can now work in their cloned folder.
-----
🚨 Extreme Risk of Data Corruption
This method is extremely dangerous for collaboration for one simple reason: race conditions.
If you and your family member `git push` at or around the same time, iCloud Drive will attempt to sync both sets of changes simultaneously. Since iCloud is just a file-syncing service and not a transactional Git server, it has no mechanism to lock the repository or resolve these conflicts. This will shred the internal Git database, corrupting your repository and likely resulting in the loss of your commit history.
-----
The Correct and Safe Alternative
The standard and safe way to share a Git repository is to use a dedicated hosting service. They are built for this exact purpose and manage collaboration safely.
GitHub
GitLab
Bitbucket
All of these services offer free private repositories. You can create a private repository and invite your family member as a collaborator. This is the professional standard and the only method you should use for any important project. |
|
|