Create Public Git Repository

Git is a distributed versioning control system for handling projects of all sizes with speed and efficiency.

It is very easy to learn even if you have minimum experience with Linux.

You can use for example GitHub repository for hosting your projects or you can create your own repository on VPS.

And that is what are we going to do now, build our own Git repository.

 

To find out more about Git, go to our tutorial with basic Git operations


1. Install Git

sudo apt-get install git

2. Add user for your repository

After we installed git, we need to add group for our git user:

sudo groupadd git

Then add user to group git:

sudo useradd -G git gituser

And finally set password for our user:

sudo passwd gituser

Enter password for your user and you’re done with this step.

3. Create public Git repository

Go to apache web directory:

cd /var/www

And make a new folder for your repository:

sudo mkdir repository.git

Now we need to set some permissions to secure our repository:

sudo chmod -R g+ws repository.git
sudo chgrp -R git repository.git

4. Initialize Git repository

Go to repository directory:

cd repository.git

Type following command to initialize bare git repository in this folder:

git --bare init

You need to run the following command to make repository shared:

sudo git config core.sharedRepository true

5. Test your new repository

Before we begin, you need SSH access to your server.

If you don’t know how to setup SSH access, see our SSH Server tutorial.

You can use any Git tool or some IDE for testing repository.

I will use PHPStorm in this tutorial to test repository (see PHPStorm Installation).

Go to VCS > Checkout from Version Control > Git

For Git Repository URL type:

ssh://gituser@site.com:/var/www/repository.git

For Parent Directory type:

/home/username/Projects

Note: Use path for your projects, this is an example

For Directory Name type:

GitProject

Note: This is example, you can type any name you like for your cloned repository

When you’re finished, the window should look like this:

Git Checkout

After that click on Clone button.

Type password for your gituser you created in Section 2.

Your repository will be cloned if everything went fine.


 

You can now add some files and try to Push to your repository to see if everything is working.

If Push command succeeded, your repository is ready for use.

Happy coding!

Leave a Reply

Your email address will not be published.