Can I push/pull directly from my google drive online?

No, you can't. There's no git running on Google drive.

I would also suggest against Google drive/Dropbox based solutions, and go for a git hosting solution instead. For example Bitbucket which offers some free private repositories. You can find some comparison information about different git hosting sites here.

As people have pointed out (and as OP already knows), you can put the bare repository inside your local Google Drive/Dropbox folder and work with that, however, there are caveats. The cloud services have their own systems for merging conflicts, and that doesn't really work with git. Consider the scenario:

  • You work with device A offline, push some commits to the bare repository in Google Drive folder, but because you are offline, those changes do not sync to the cloud.

  • You then forget about it, work with device B online, push commits to Google Drive folder, and those changes do get synced.

  • Device A becomes online - you now have a conflict in Google Drive.

This is, of course, recoverable, but inconvenient. I therefore recommend to use a solution that is designed precisely for git hosting.


Here is a very good article on the subject (archived version here, with the relevant parts reproduced here):

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."

Change the directory to where your Google Drive is located and initialize a bare repository:

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

Go back to your working directory:

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

To clone your Git repository from Google Drive:

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