Saturday, July 16, 2016

How to Import Existing Git Repository and Upload into Git Server

Say you have a local git repository called my_project in your home folder ~ of your local machine, and you'd like upload this into your personal git server. Here is how you can do this. For more info, please refer to here.

First, make sure that your git repository folder exists in the working directory.
$ pwd
/home/your_username/
$ ls
my_project/
...

Then, create a bare git repository from the existing repository
$ git clone --bare my_project my_project.git

You should now have the cloned bare repository
$ ls
my project/
my project.git/
...

Noe that .git ending is a conventional indication of server repository.

Next, copy the cloned repository to your server, usually through scp
$ scp -r my_project.git git_server_user@your.git.server:/git/

Here, you will need to replace git_server_user, your.git.server, and /git/ with the appropriate server username, server address, and destination path in the server, respectively.

That should be it. Now, to clone from your server, simply run the following from a client system
$ git clone ssh://git_server_user@your.git.server:/git/my_project.git

Of course, you may want to delete the bare repository from the local machine (not the server).
$ rm -rf my_project.git

That should do it!

No comments:

Post a Comment