How to Run Your Own Git Server

Source: Internet
Author: User

Reference: Https://www.linux.com/learn/how-run-your-own-git-server

Install Git on your server

In this tutorial we is considering a use-case where we have a remote server and a local server and we'll work between t Hese machines. For the sake of simplicity we'll call them Remote-server and local-server.

First, install Git on both machines. You can install Git from the packages already available via the repos or your distros, or your can do it manually. In this article we'll use the simpler method:

sudo apt-get install Git-core
Then add a user for Git.

sudo useradd git
passwd git
In order to ease access to the server let ' s set-up a password-less ssh login. First create SSH keys on your local machine:

SSH-KEYGEN-T RSA
The It would ask you to provide the storing the key, just hits Enter to use the default location. The second question'll be is to provide it with a pass phrase which would be needed to access the remote server. It generates KEYS-A public key and a private key. Note the location of the public key which you'll need in the next step.

Now, there are to copy these keys to the server so, the machines can talk to each of the other. Run the following command on your local machine:

Cat ~/.ssh/id_rsa.pub | SSH [email protected] "Mkdir-p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Now ssh to the server and create a project directory for Git. You can use the desired path for the repo.

[Email protected]:~ $ mkdir-p/home/swapnil/project-1.git
Then change to this directory:

Cd/home/swapnil/project-1.git
Then create an empty repo: repository on the server

Git init--bare
Initialized Empty Git repository In/home/swapnil/project-1.git
We now need to create a Git repo on the local machine.

Mkdir-p/home/swapnil/git/project
and change to the This directory:

Cd/home/swapnil/git/project
Now create the files, the need for the project in this directory. Stay in this directory and initiate git:

Git init
Initialized Empty Git repository In/home/swapnil/git/project
Now add files to the repo:

git Add.
Now every time and add a file or make changes you have to run the add command above. You also need-write a commit message with the every change in a file. The commit message basically tells what changes were made.

git commit-m "message"-A
[Master (root-commit) 57331ee] Message
2 files changed, 2 insertions (+)
Create mode 100644 GoT.txt
Create mode 100644 Writing.txt
Had a file called GoT (Game of Thrones review) and I made some changes, so when I ran the command it SPECIF IED that changes were made to the file. In the above command '-a ' option means commits for all files in the repo. If you made changes to only one you can specify the name of this file instead of using '-a '.

An example:

git commit-m "message" GoT.txt
[Master E517B10] Message
1 file changed, 1 insertion (+)
Until now we have been working on the local server. Now we had to push these changes to the server so that the work was accessible over the Internet and you can collaborate with O Ther team members.

Git remote add Origin ssh://[email Protected]/git-respo-path-on-server
Now you can push or pull changes between the server and local machine using the ' push ' or ' pull ' option:

Git push Origin Master
If There is other team members who want to work with the project they need to clones the repo on the server to their L OcalMachine:

git clone [email protected]:/home/swapnil/project.git
Here/home/swapnil/project.git is the project path to the remote server, exchange the values for your own server.

Then change directory in the Local machine (Exchange project with the name of project on your server):

Cd/project
Now they can edit files, write commit change messages and then push them to the server:

Git commit-m ' corrections in GoT.txt story '-A
And then push changes:
Git push Origin Master

How to Run Your Own Git Server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.