Sometimes I would like to backup my codes to the cloud, even for some teeny-tiny projects. Some of these codes, however, are either not ready for the public or too shameful to let others see, so that I would not bother using the Github public repositories with them. Github for education offers free private repositories for students, but the number is limited to 7 and does not have very large space. That makes using OneDrive/Dropbox an option.

Here is an example. First we create a test project.

mkdir foo
cd foo
git init
echo "test" > README.md

Then commit the changes as usual.

git add --all
git commit -m "first commit"

Create an empty repository in the sync folder, and add it as a remote.

git init --bare ~/OneDrive/foo.git
git remote add OneDrive ~/OneDrive/foo.git

Push the code to the repo.

git push -u OneDrive master

The code should be synced to the cloud. You can access the codes from other terminals.

git pull
or
git clone ~/OneDrive/foo.git

The method should be fine for backup purpose. But,

  • Do not push from multiple terminals simultaneously, the repo could be damaged.
  • Do not use it for cooperations, unless you can shout to your partner you are gonna push.
  • Make sure the changes are synced before pulling from other places.