I backup my local git repositories on OneDrive

It’s actually not as stupid of an idea as it sounds

Alexis Lucattini
4 min readJan 31, 2021

“GitHub and OneDrive are now both Microsoft products” — this was my single justification one day for deciding “f***-it, what’s the worst that could happen if I dragged and dropped all of my local GitHub directories into OneDrive? At least it would be a funny anecdote to tell to my colleagues in the virtual Monday morning meeting”.
As it turns out, so far, touch wood, disaster is yet to strike. In fact the benefits, have greatly outweighed any consequences.

Placing my local repos through my OneDrive has reduced my need for the endless adding/committing/pushing unready files to GitHub just to start working from another device

The over-flexible work dilemma

Like many of us, I’ve been stuck working at home for the last year. I have a (until recently dormant) MacOS desktop in my office, a Windows 10 desktop that I’m writing from right now in my bedroom, and a Windows 10 laptop for when I want to work from somewhere else in the house. Working from three separate disconnected devices made working with git a nightmare.

Even pre-pandemic, any uncommitted late-night work from home wasn’t available for me to continue working on when I rocked up at the office the next morning, nor were any of the large test datasets that are too large or not appropriate to be git-controlled. I’ve also recently found myself with sweat sticking my legs to the chair as I desperately commit and push unfinished scripts to GitHub on my bedroom desktop where the room has reached 30° C, just so I could work off my laptop in the lounge under our air-conditioner.

This continuous committing and pushing leads to poor developer practices; half-finished code chunk commits, rushed commit messages, and the wrong files being added to the repo.

Solving the Git Overhead

Do not get me wrong, GIT IS GREAT!! For our team where we’re all working remotely, GitHub has been essential for us to share / validate / branch and version control our scripts and software. git does, however, have its overhead as mentioned above. If only there was something that synced all my stuff automatically, including the things that I don’t want to commit to public repos — say secrets in text files, that I would like to have available to me on my other devices…

…Introducing OneDrive! While commands such as git stash / git merge / git rebase will throw the little blue cloud icon in the corner of my screen into chaos mode, it quickly recovers into a synced state . The set of files I want to currently put out of the way but not delete— known as a stash — are available to me instantly should I decide to ‘pop’ them when working from another device. Whether I’m working from the lounge room, a café, or from the office again, I no longer need to worry about syncronising my work from my home desktop.

You’re playing with fire, surely something has to go wrong?

My only caveat so far, are the files that you don’t want synced between computers. The main culprit of these for me have been PyCharm JetBrains .idea files that sit in the top directory of each repository / project. Unfortunately, OneDrive doesn’t let you ignore files of a certain type or in a certain folder in the same way git does. Therefore, every time I switch from my Windows to Mac or vice-versa, my PyCharm project configuration breaks for each repo.

My solution to this has been to sit the project files outside of OneDrive and add the git repo into the content root of the project. That way, each device has its own isolated copy of the project configuration.

The PyCharm project can be created in a local directory to prevent conflicting ‘.idea’ folders. The git controlled repo can then be added via the Project Structure settings in PyCharm.

OneDrive, the git --regret saviour

Again, I need not remind you that git is great. Yet, there’s always a risk of accidentally deleting very large amounts of important code by not realizing the consequences of the the commands that you’re running.
git pull --force, git reset --hard, and git checkout --are three commands to which all software engineers have run at some points in their career that have then been followed by tears.

Yet, the part that chuffs me the most about this daring experiment has been the discovery that my hesitations working with git now has a safety net. OneDrive works with time-based version controlling. Any poor choices I make can be easily fixed by going through OneDrive’s ‘restore’ setting and rolling back in time.

OneDrive allows for a restoration of files with changes listed in chronological order

Proceeding with caution

I can’t say this is an option for everyone. I am always careful that I don’t ever shut down my computer immediately after running any git commands, but I am also fortunate that both my home and work desktops are connect to the internet via Cat6-ethernet cables — the kilobytes of file changes are synced in a few seconds. I dare say there may come a time where my luck falls apart and I’m asked to resolve a OneDrive conflict. Until that day, I’ll continue this insanity.

--

--

Alexis Lucattini

Bioinformatician / Research Software Engineer — University of Melbourne Centre for Cancer Research, Melbourne, Australia