Using Git to create a source code repository on the server side

Source: Internet
Author: User
Tags using git

The following is a simple procedure for building a Git repository on a server.

Installing the Git Program

Git is distributed, that is, the program does not differentiate between the server and the client, and most of the official sources of Linux distributions have it, such as installing Git in ArchLinux:

$ sudo pacman-s git

However, some distributions are not, such as CentOS, need to add EPEL source , but even if the use of EPEL source, the version is also the current mainstream version of a big difference, then the best way is to install through the source code. Here are the commands for adding EPEL and installing Git in CentOS 5.

$ sudo rpm-uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm$ sudo yum install git
Create a Git source repository

For simplicity, you can create a Git repository in the following ways:
1. Create a dedicated user.
2. Create a Git blank repository under the user's home directory.
3. Add the SSH key of all the developer computers to the user's ~/.ssh/authorized_keys file so that the developers have access to the Git repository, while the other users do not have any permissions.

This procedure is shown below:

$ sudo useradd git #创建一个名字为git的用户 $ sudo passwd git #更改该用户的密码 $ su-git #切换到该帐号 $ mkdir project1.git #创建一个项目源码仓库目录 $ cd Proje ct1.git$ git--bare init #初始化一个空白仓库

The following are performed on the developer's computer:

$ ssh-keygen # Generate SSH key$ Ssh-copy-id [email protected] # Copy the SSH pub key ID generated in the previous step to the server.

When developers use Git to access the repository, they actually transfer the file via SSH, so the address of the repository is the same as the SSH location remote file, such as the address of the Project1.git:

[Email protected]:p Roject1.git

Then the command to clone this warehouse is:

git clone [email protected]:p Roject1.git


Client

Git init

echo "First file" >> README

Cat README

git Add.

Git commit-a-M "Add README"

Git remote add Origin ssh://[email Protected]/~/workspace/code_celloct/project1.git

Git push Origin Master

git clone [email protected]:/home/git/project1.git

If Project1.git is located in ~git/repositories/project1.git, the address above will be changed to
[Email Protected]:repositories/project1.git

Using Git to create a source code repository on the server side

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.