Version control-Build a git server

Source: Internet
Author: User
Tags git clone repository

GitHub is a GIT server that hosts open source code for free, and if we don't want to expose the source code of the project and don't want to pay for it, we can build a git server ourselves.

Let's look at how to build a git server on Ubuntu. We use VMware virtual machines to install two Ubantu systems, named Gitserver and Gitclient_01, respectively.

1, install OpenSSH and configure SSH login without password

  Install the SSH service by ordering sudo apt-get install openssh-server.

Use the command ps–e|grep SSH to see if the SSH service is started.

Through the above command, we install the SSH service for Ubantu system, and configure SSH login without password, first we modify the host and IP configuration file: gedit/ect/hosts

2, create user git, used to manage running Git service.

3. Configure SSH login without password

On gitclient_01, we use the command: ssh-keygen–t RSA to generate the key, as

After completion, in the. SSH directory, we can see the Id_rsa and id_rsa.pub files, id_rsa.pub as the public key, we scp/home/git/.ssh/id_rsa.pub gitserver:/home/by command Git copies the public key generated on the gitclient_01 to the Gitserver.

On Gitserver We first look at whether Authorized_kesys files exist under the/home/git/.ssh directory,

If not, you can create this file from Touch Authorized_keys.

After the Authorized_keys is created, append the contents of the public key id_rsa.pub copied on the gitclient_01 to the Authroized_keys, note that it is appended to the file, and you can use the command cat/home/git/id_ Rsa.pub>>/home/git/.ssh/authorized_keys.

When the above content is complete, we can use the command SSH gitserver to complete the login without password in gitclient_01.

4. Install git

Install git via the command sudo apt-get install Git-core

5. Create a storage directory for the Git repository.

6. Initialize the server-side warehouse

Initialize the warehouse using the command Git–bare init/home/git/myrep.git

7, on the gitclient_01, through the git clone command to clone the remote repository, and run the development on their own computers.

Git clone[email protected]:/home/git/myrep.git

With the above steps we have completed the construction of the GIT server, after the completion of the building, we need to understand the GIT server in the process of interaction with the command. The main commands are git clone, git remote, git fetch, git pull, git push, and so on.

1. Git clone

This command is the first step in our interaction with the remote repository, where we can clone the remote repository locally, as in the 7th step above, we use this command to clone the remote library locally.

Syntax: Git clone repository URL local library name

The local library name can be omitted, and a directory with the same name as the remote repository will be generated locally when omitted.

2. Git remote

This command is used to manage the remote host name, which can list all hostnames without parameters.

Show Origin is when you clone a remote repository using the Clone command, and git automatically names the remote host.

You can view the repository URL by ordering git remote–v.

3. Git fetch

This command updates the remote version library to the local library.

Syntax: Git fetch host name

By default, GIT fetch origin will update all branches on origin of the remote host, and if you want to update only one branch, add the branch name after the host name origin.

Syntax: Git fetch Origin Master

4. Git push

This command is used to push updates from the local branch to the remote host.

Syntax: git push remote host name local branch name: remote Branch Name

If you omit the remote branch name, it means that the local branch is pushed to the remote branch that has the final relationship, and if the remote branch does not exist, it is created.

For example, GIT push Origin master, which means that the local master branch is pushed to the master branch of the Origin host.

If you omit the local molecular name, it means that you want to delete a branch from the remote host, such as Git push origin:master, to delete the master branch in the Origin host

5. Git pull

This command is used to get updates from the remote branch.

Syntax: GIT pull remote host remote branch: local branch such as: Git pulling origin master:master, which means that the Master branch in origin of the remote host is followed by the new to the local branch master.

If you have any inquiries or technical exchanges, please join the official QQ Group: (452379712)

Jerry Education
Source:http://blog.csdn.net/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and CSDN Common, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Version control-Build a 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.