Do I have a functional workflow using a local Git repository and OneDrive working directory?

I’m relatively new to git and need to set up a workflow in which my working files are stored in a OneDrive directory.

If I understand correctly, this can be done so long as the local git repository is stored on my local hard drive outside of my OneDrive directory. It is also my understanding that I can set this up using: git init --separate-git-dir=.

My reason for setting my version control up in this way is two-fold: (1) I need to be able to access my working files from multiple computers and (2) I need to backup .gitignore directories and files (large data and figure files) with OneDrive

My plan is to access the working directory on multiple machines but only use git version control on one machine.

Is this a workable setup? I’ve seen many warnings about using git and OneDrive together but it appears to me that the issue is with storing the .git directories in a OneDrive directory. It seems to me that there shouldn’t be a problem if the working directories are on OneDrive and the .git directory is stored locally.

That said, I am new to git and would like confirmation from more experienced users.

I’ve attached a diagram to illustrate what I want to do. Please feel free to correct any of my vocabulary. Also happy to hear alternate strategies to obtain these goals.

And finally, if this is a workable setup, do I need the file structure “…\GitHubRepositories\Project1.git” for my local repository or is it possible (or better) to use some sort of custom name for the repository so that the file structure is something like “…\GitHubRepositories\Project1.git”.

Thanks!

Git-OneDrive Workflow Diagram

Yes, your setup is workable and makes sense.

Key Idea:

  • Working directory on OneDrive: Fine
  • .git directory stored elsewhere (outside OneDrive) using --separate-git-dir: Correct and safe

Your Goals:

  1. Access working files across devices via OneDrive → Achieved
  2. Exclude .git from OneDrive (avoids sync corruption) → Good practice
  3. Use Git version control only on one machine → Simplifies things

Setup Steps:

  1. Create your working folder in OneDrive, e.g.:
C:\Users\You\OneDrive\Project1
  1. Initialize Git with a separate .git directory outside OneDrive:
git init --separate-git-dir="C:\GitRepos\Project1.git" "C:\Users\You\OneDrive\Project1"
  • C:\GitRepos\Project1.git → stores the Git repo metadata
  • C:\Users\You\OneDrive\Project1 → working files synced via OneDrive
  1. You can name the .git directory anything:
C:\GitRepos\Project1.git

or even:

C:\MyVersionControl\Project1Repo

What to Avoid:

  • Don’t sync .git with OneDrive (corrupts repo)
  • Don’t try to git commit/push/pull from multiple computers unless you’re syncing the .git folder too — and that’s risky via OneDrive.

If you want Git on multiple machines later:

  • Better to use GitHub/GitLab/Bitbucket as a remote repo.
  • Sync via Git, not OneDrive, across machines.

Final Summary:

Part OneDrive? Git Controlled? Safe?
Working directory Yes Yes Yes
.git directory No Yes Yes
Git operations (commit etc) Yes (on one PC only) Yes Yes