Creating a Central Git Repository

In my previous post I discussed the steps necessary to create a Git repository.   As it turns out, today I found the other piece of information that I was missing. That is, that when you create a central repository it must be bare.

If you really want to share code (collaborate with others) in a repository, your "master" or central repository should be an empty one.  That means that the only thing that it should contain is the repository but no source files (or any other files under version control). 

If you will recall, I ran into some hair-pulling problems because I couldn't push to the master repository. That was because the master branch had a working directory that had the master branch checked out.  As a result, Git refused to push changes made in the slave to the master.  By creating a bare repository you are insuring that this repository will not be worked on directly (i.e. it does not have a working directory).  Therefore by creating a bare repository you will never run into this problem.

You can create a bare repository by following the commands below.

$ mkdir myproject.git
$ cd myproject.git
$ git --bare init

That's all there is to it.  That will create a bare repository that can then be shared using the file system.  The directory in this example looks like this on my computer.


You can name the directory anything you want.  I just named .git so that anyone would know that it's a Git repository and also by convention when Git clones it, Git drops the .git portion of the folder name in your local copy.

Like I said before, I am still learning, which means that information I've yet to learn may discredit the approaches that I've taken thus far.  Hope you enjoyed this post and if you read it please provide your feedback.   I always appreciate feedback, even if it's negative.

Comments

Popular posts from this blog

Simple Example of Using Pipes with C#

Difference Between Adapter and Bridge Design Patterns

Remote Access to Your Home Desktop Using No-IP