Easy creation of a git repository on OneDrive

Published on October 02, 2018

Easy creation of a git repository on OneDrive

  • Tutorial
Hello. I decided to write a cheat sheet for the future to a greater extent, but it may be useful to someone else.

Surely by git experts and all so well aware of it, but one Habré looking for solutions to their problems and a lot of newbies beginners, like myself, who are more than a reader, not a writer.

Introduction


It all started when I began to think ... And I thought about how interesting it would be to organize my homemade homework reliably so as not to lose anything, and preferably fashionably correctly using git and the like.

Of course, many will say GitHub . Yes, of course, a good solution, but ... There are some, but such a solution.

Not all homemade want to spread in open access. Something is just a shame for others to see, something I don’t want to show, at least for a while. And closed repositories on GitHub are available only on a paid account.

But homemade homemade - this is not the level for which you want to pay monthly. They do not bring income, but are written for the soul, who has programming life's hobby.

And then I drew attention to my laptop for such classes, and there quite by chance was a licensed Windows 8.1, in which an element like OneDrive always loomed and came to my hand.

Who does not know, this is a cloud disk from microsoft for account holders.

Why not organize a git repository on this cloud.

I began to look for information on this topic, on the Russian-language Internet, something somehow did not come across, there was some information on foreign ones, but for some reason no solution was right for me.

Looking ahead, I’ll need links in addressing git, but not the windows path, indicating the disk, etc.

Many suggested installing an additional console utility curl or similar, but really did not want to do this and get by with the standard windows and git client tools under windows.

Therefore, I collected crumbs from various sources in a working solution, at least for me.

I have 5 GB of free space available, not very much, but for my needs - more than. So why bother good?

If someone seems too little, you can always buy more space.
Well, I digress from the topic. And so we proceed to the actual organization of the repository.

Assumptions


Immediately discuss some of the details, for ease of understanding the following steps.
Let's go to OneDrive and create a git directory in which we will place all our repositories.
Suppose our username is User.

Then the folder for OneDrive synchronization will be located at: C: \ Users \ User \ SkyDrive \ .

It should already be, we created, the directory git.

Well, for example, we will organize the project project1.

Immediately in it we will create a .gitignore file for exceptions, which need not be committed.

As I write in python, my file contains the following:

*.gitignore
*.log
*.pyo
*.pyc
__pycache__/

In the current, which I use, python 3.5 compiled files pyo and pyc are already added to the __ pycache __ / folder, so if you have this line you can not write them, but when I started with python 3.3 - they lay next to the source code files, so they remained. Do not interfere and well.

For django projects, the following lines are added to the above:

db.sqlite3
staticfiles/

Of course, when running django on any hosting, the database will be more serious, for example postgres, or what hosting provides. But during development, you can use good old sqlite for debugging.

In the project directory, right-click on the context menu and select the “git bash here” option .

I think when installing the git client you chose the option of integration into the explorer.

This is important for use on the path to the repository ~ (tilde) . Since the standard windows console does not know how to work with this symbol, in bash it means the home directory, and the path itself is of interest to us: C: \ Users \ User \ .

This mode is only needed for the first time when creating a repository in order to assign a link to the repository in the local settings of the git project.

The whole sequence of actions


In the git bash console, we write the following instructions.

I will give them a complete list at once, and then chew in detail.

git init
git add --all
git commit -m "init"
git init --bare ~/SkyDrive/git/project1.git
git remote add OneDrive ~/SkyDrive/git/project1.git
git push -u OneDrive master

We will analyze each step in detail.


1. git init

Just create an empty local git project repository in the project folder itself.

2. git add --all

This action is intended to add to index all the files in the directory and its subdirectories, except of course the contents of the .gitignore file.
You can also use: git add .
But it adds all the files from the directory, not including the subdirectories.
So it depends on the complexity of your project. Who is more convenient to use - choose for yourself.

3. git commit -m "init"
Actually our first commit. For now, locally, without adding to the cloud repository.

4. git init --bare ~/SkyDrive/git/project1.git
And here is the first call to the remote repository. Here we create a repository for this project.

Important! The --bare key is required. It indicates to create a master branch in this repository. Although it is still empty.

.git at the end of the path after the project name is not necessary, but, as I understand it, this is a well-established tradition. As for me, it is quite convenient, I see no reason to change it.

5. git remote add OneDrive ~/SkyDrive/git/project1.git
And here we assign the name OneDrive for our link to the remote repository.

6. git push -u OneDrive master
And the last step is to upload the contents of our project to the master branch of the remote repository.

Such a record is needed only for the first time to fill the master branch. In the future, you can use the standard: git push.

And the git bash mode is no longer required. Further work with git in this project is possible from the usual windows console.

Well that's all. Very simple way, but it allows you to join the world of real developers and feel almost like a pro.