I have been looking for a free solution for sharing code when working on private projects – where I don’t have access to business servers for sharing code. I found a very easy way using git and OneDrive (should also work with Dropbox or GoogleDrive).
Before we begin make sure that you have the client version of the service (and are logged in). In my case that is the OneDrive client. The client should be visible in the windows toolbar.
The client application mounts the cloud to your local folder.
This can be useful when working with private code that you would like to share.
Create new git repository in the onedrive folder.
I will use the existing folder ‘myDev’ in OneDrive for the new repository.
First you need to open a git bash (requires that git are installed).
This will open up the command line for running git commands.
Now run the command ‘git init –bare’. The ‘bare’ parameter creates the repository as a master repository in the directory (you will not be able to see the actually files that you commit in this folder. It works kind like a database).
This command will initialize a git repository as master. The ‘bare’ parameter tells git to initialize it as a repository and not just as a working directory.
You can verify that the repository was created by opening your OneDrive and see that the directory now contains the files for the git repository.
You have now created the repository on your OneDrive and are now ready to clone the repository to your local drive and start working.
Cloning remote repository from OneDrive to your local disk
Find a local directory where you want to have your working directory. Open the git bash in this location and use the git clone command.
Remember to use 3 ‘/’ after the file like ‘file:///’.
This command will clone your repository to your working (local) directory.
Working with your local files and commit to OneDrive
You are now able to create new files in your working directory and alter files for later commit/push to your OneDrive.
I have created an empty file in my working directory.
To get this file into the master git repository will forst need to add the file to git, make a commit and then a push to the repository.
This command adds the file to git.
Then you need to make the commit.
This will push your file to the repository – ready for other to clone it and work on it.
You are now ready to work with code and sync it with OneDrive (you could also use github but then you will have to pay for it if you need to work privately).
If you are more than one person making a commit at the same time you might experience problems with git over OneDrive. You should therefore not create multiple commits at the same time (this has to do with the local sync that OneDrive are doing).