How to use Google Drive or Dropbox to host your private Git repositories

This was something that I needed to do (for my own personal and private projects). While there are many ways out there to host your private repositories such as the awesome Bitbucket, Github, etc, I was looking at much simpler solution just for myself. All I needed is a versioning system to keep my source codes.

In this tutorial I'm going to demonstrate how easy it is to host your own Git repositories in any of your preferred cloud providers. I chose Google Drive personally.

Lets say you have a project named "johndoe" with a file "README" like below:

/var/www/html/johndoe/
/var/www/html/johndoe/README

Initialise an empty Git repository here.

$  cd /var/www/html/johndoe
$  git init
$  git add README
$  git commit README -m "Initial commit."

Now for the fun part. Change directory to where your Google Drive is located and initialise a bare repository.

$  cd /Users/myusername/Google\ Drive/
$  mkdir johndoe
$  cd johndoe
$  git init --bare

Getting back to your working directory..

$  cd /var/www/html/johndoe
$  git remote add origin file:///Users/myusername/Google\ Drive/johndoe
$  git push origin master

Walla :)

Edit: How to clone your Git repository from Google Drive

I missed this part earlier, adding to this article..

$  cd /var/www/html/johndoe2
$  git clone file:///Users/myusername/Google\ Drive/johndoe

28 comments for 'How to use Google Drive or Dropbox to host your private Git repositories'

Karl's picture

hi, thanks for your sharing.

I want to know that everytime machine1 commited a file, machine2 needs to clone again(download all files)?

admin's picture

No you don't need unless there are multiple cloned repositories of the same one.

From my article there is only 1 host repo and a client repo.

When you commit a file, any other cloned repo will need to run git checkout to update.

I hope that answers your question?

Andy Simpson's picture

Google Drive is really wonderful to use! I enjoyed your tutorial and personal experience about the process of demonstrates hosting. I am interested to follow your instruction properly. Thanks for sharing this nice experience. Keep it up...
cheap host oath

Saad Rehman's picture

But how do I give the address of my repository for someone else to clone from? The command you mentioned for cloning can be used to clone if I have google drive on the other machine, and it has downloaded the code to it. Let's say I want to share the code with friend, but want to share my google drive account with him. How do I go about it?

admin's picture

Well, if I were you I would use free private Git hosting like the awesome Bitbucket and share with your friends.

This tutorial with Google Drive thingy was more of a personal backup of your own Git repositories. Its quite inconvenient.

Saad Rehman's picture

Oh thank you then. What I do to that end is that I create my workspace in the Dropbox in the first place. No need to create twin repos. Just create the repo in dropbox, commit there, clone from there, etc etc.

admin's picture

Yeap! =)

Thats exactly, what I'm doing right now.
Make a symlink of your htdocs to Dropbox folder, so whatever changes gets sync-ed. This is much much easier since Dropbox has its own versioning system too!

anderstood's picture

Hi, thanks a lot for the tutorial!

Create the project in the sync-ed folder may be restricive. Why not simply do something like [git clone project_path gdrive_folder] and then run grive command? I think it is what i'm going to do. But it requires to rm the project in the gdrive_folder every time before cloning.

I'm open to any drawbacks of my solution!

hovavo's picture

Thanks for the article!
I've followed your example, and i'm getting these errors:
'atal: Reference has invalid format: 'refs/heads/Icon
It seams that (on mac) Google Drive adds a hidden icon to each directory, and that breaks pushing and cloning of the repository.
Anyone else experiencing that too?

Jonathan's picture

Yes, I just discovered that I am experiencing this also. When installing Google drive I had to explicitly authenticate it to have permissions to add these icons, but I didn't know at the time that it would be a problem. Not sure what to do yet...

Dan Martin's picture

I'm curious, can you explain why you choose to create a second repository in Google Drive, and push to that? Why not create your working repository in your Google Drive folder, and work directly within that?

admin's picture

You would need a bare repository to allow commits to be pushed here.
This will be the main repo itself. I hope I got your question right?

Dan Martin's picture

If you place your entire project in your Google Drive folder, and then create your repo within that working directory (as is standard), you don't need to push. Both the state of your working directory, plus the commit history to that git repo is going up to Google Drive. Even if you want to keep your working directory outside of Google Drive, and only place the repo into Drive, it would still work fine.

I'm asking, mainly because I already do it the way I describe, and it works fine. So I was curious why you choose to add the complexity of a git push into GDrive.

Akinjide agboola's picture

This may not be a real solution, does that mean different users, if you need them, have to use one Google account on their different computers to get files sync?

Anyway, it could help keep track of code development within one machine serving as a git server and client.

admin's picture

Yes its not a real solution, its meant for very personal Git repository.

If you want it to be used with different users, you can use the free awesome service by Bitbucket.

Kirubaharan Palani's picture

If we go with Google Drive, is it possible to share the repository and track the changes?

admin's picture

I'm not quite sure about that. If you want to do that already, why not go for a hosted solution that is free and reliable such as bitbucket.org ?

Kirubaharan Palani's picture

Thanks,
Now I am using bitbucket.org only. Today only i saw your blog regarding "How to use Google Drive or Dropbox to host your private Git repositories". So i got doubt regarding the Tracking.

Ahmed's picture

You need to learn Git hooks, shortly they are custom scripts for your needs, after committing or pushing your changes. An example usage of this hooks, source code checked if it written according to coding-naming standarts. Otherwise push is rejected by server.

Git Hooks

abbas's picture

All those guys asking about sharing the repo with others, don't they know google drive allow you to share your folder with anyone you want.

Matt's picture

Instead of using Google drive, why don't you guys try Hostgator. It's fast, reliable, Eco friendly and the most important, very cheap. I will strongly suggest you this option :)

Add new comment