52

There are methods to sync my local git repository over to my google drive via google drive sync windows application, but I was wondering whether I could bypass its need altogether.

Fro eg.

$ git remote add origin https://drive.google.com/<my_folder>/<my_repository>.git
$ git push github master
laggingreflex
  • 32,948
  • 35
  • 141
  • 196

6 Answers6

53

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.

1615903
  • 32,635
  • 12
  • 70
  • 99
  • 4
    it is possible, check other answers, accepted answer should be changed. – Amr Lotfy May 25 '14 at 11:07
  • 1
    @AmrLotfy It's not possible the way OP wants to. Having the bare repo in Google drive folder is not what he is asking. – 1615903 May 27 '14 at 16:32
  • 1
    @user1615903 `I would also suggest against Google drive/Dropbox based solutions` Why so? – Kshitiz Sharma Jul 08 '14 at 06:17
  • I was thinking about using drive for my hosting so it would sync up in the background. Google Drive does not offer custom domain services but I think gweb.io does. Correct me if I'm wrong. – zachdyer Jul 12 '14 at 05:47
  • Dropbox works fine with git: http://www.nssl.noaa.gov/users/lwicker/public_html/HowToUseGitandDropbox.pdf – Nex May 21 '16 at 22:40
  • @Nex Yes, however, that was not what OP was asking, as I said in the previous comment. – 1615903 May 23 '16 at 06:06
  • This is technically the correct answer. However, cloud drives like google's can be an extra piece of mind as a quick backup of a local repository that it's not yet pushed publicly. They are not perfect and they may rarely need maintenance of duplicate files if one works with multiple computers but they have reached some maturity in not losing data. – j riv Feb 14 '17 at 11:42
  • Although it is not a good practice, it is a necessary workaround when using purely cloud-based code execution platforms, such as Google Colab. – rwong Jul 11 '23 at 21:45
24

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
Haralan Dobrev
  • 7,617
  • 2
  • 48
  • 66
  • 2
    @Michael archived [here](https://web.archive.org/web/20161204062829/http://kahthong.com/2012/05/how-use-google-drive-or-dropbox-host-your-private-git-repositories) – lucid_dreamer Jun 07 '17 at 23:06
  • @refi64 how so? I don't see anything Windows specific. If anything there were reports of *problems* on Windows (impliying it works on Linux). – lucid_dreamer Jun 07 '17 at 23:08
  • I don't think you need the `file:` qualifier - so maybe that is the Windows issue referred to above? – colm.anseo Mar 29 '18 at 18:46
6

Eduardo Rosas has an article on how to do this using colab (only a browser required). essentially you access your google drive using:

from google.colab import drive
drive.mount('/content/gdrive')
#cd to the google drive you using the magic command
%cd /content/gdrive/'My Drive'/[your drive folder for repo]
#check your directory location with
!pwd
#clone your repo - Note this exposes your password so don't make the notebook public
!git clone https://LaloCo:password%23@github.com/LaloCo/handson-ml.git
#I find using a github personal access token easier
!git clone https://user:PAT@github.com/repo
rwreed
  • 348
  • 2
  • 10
3

You could use itDuzzit, they provide direct cloud-to-cloud syncing between Google Drive and GitHub. They have a fairly limited free tier and several paid ones. As long as your code is opensource and/or you don't mind a third-party handling it, this could be a viable solution.

A.R.
  • 1,888
  • 2
  • 14
  • 22
1

If you are running a Unix shell and have Google Drive locally installed on your machine, you can add a script to your .bash_profile or .zshrc file like this...

# Initialize a remote repo on "local" Google Drive and push to it for safekeeping.
function mkr() {
  CWD=$(PWD)
  REPONAME=${PWD##*/}
  REPOPATH=/Users/Bob/Google\ Drive/Repos/$REPONAME
  mkdir -p $REPOPATH
  cd $REPOPATH
  git init --bare
  cd $CWD
  git remote add origin $REPOPATH
  git push origin master
}

Assuming you have already run git init, you can type mkr from the command line inside your local project directory. After this mkr step, you can run git push like normal as if it lives on GitHub, Bitbucket, etc. You just won't have the usual niceties from the remote side.

bholben
  • 1,077
  • 1
  • 15
  • 24
0

You can use google collab for the purpose.

  • Upload your files directly int your google drive
  • Open google collab
  • import files
  • install git (As Jupyter notebook or Linux PC)

and you are done