Git server construction in CentOS 6.5

Source: Internet
Author: User
Tags email account git client version control system website hosting

1. Version Control

Version Control is a system that records changes in the content of one or more files for future reference to specific version revisions. There are three version control systems:

1. Local Version Control System

Many people are used to copying the entire project directory to save different versions, and may change the name and backup time to show the difference. The only benefit of doing so is simplicity. But there are also a lot of disadvantages: Sometimes the working directory will be confused, once the wrong file is lost data, there is no way to cancel the recovery.

To solve this problem, many local version control systems have been developed a long time ago. Most of them use a simple database to record the previous update differences of files. As shown in the following figure,

2. Centralized Version Control System

Centralized Version Control Systems (CVCS) allow developers on different development Systems to work together. Such systems, such as CVS, Subversion, and Perforce, all have a single centrally managed server that stores the revision of all files, people working collaboratively connect to this server through the client to retrieve the latest files or submit updates. Over the years, this has become the standard practice of version control systems.

3. distributed version control system

Distributed Version Control System (DVCS), such as Git, Mercurial, Bazaar, and Darcs. The client does not only extract snapshots of the latest versions, instead, the code repository is fully mirrored. In this way, any server that works collaboratively can be recovered from a local warehouse from any image. Because every extraction operation is actually a complete backup of the code repository,

Furthermore, many such systems can specify to interact with several different remote code repositories. By default, You can collaborate with people in different teams in the same project. You can set different collaboration processes as needed, such as hierarchical workflow, which cannot be implemented in previous centralized systems.

2. About Git

Git is a perfect Implementation of the distributed version control system. Its basic differences with the centralized version control system SVN are as follows:

  • Git is distributed, while SVN is not

    Git and SVN have their own centralized version libraries or servers. However, GIT is more inclined to be used in the distributed mode, that is, each developer will clone a version library on their own machine after chect out code on the central version Library/server.

  • Git stores the content in metadata mode, while SVN stores the content by file

    All resource control systems hide the object metadata in a folder such as. svn and. cvs. If you compare the size of the. git directory with that of. svn, you will find that they are quite different. Because the. git directory is a clone version library on your machine that owns everything on the central version library, such as tags, branches, and version records.

  • Git branch and SVN Branch

    The branch of SVN is another directory in the version library, while the branch of Git is a snapshot of the entire version library, and can be quickly switched between several branches under the same working directory.

  • Git does not have a global version number, while SVN does

    The SVN version number is actually a source code snapshot of any corresponding time. Git does not have such a global version number, which is also the biggest feature missing by Git.

  • The content integrity of Git is better than that of SVN

    Git uses the SHA-1 hash algorithm for content storage. This ensures the integrity of the Code content and reduces the damage to the version library in case of disk or network problems.

The basic workflow of Git is as follows:

  • Modify some files in the working directory.

  • Take a snapshot of the modified file and save it to the temporary storage area.

  • Submit the updates and permanently dump the file snapshots saved in the temporary storage area to the Git directory.

3. Git server Construction

1. Environment deployment

System Environment: SERVER: CentOS 6.5, ip: 192.168.56.1

Client: CentOS 6.5, ip: 192.168.56.101

Software Version: SERVER: source code compilation and installation, git-1.9.0.tar.gz

Client: yum online installation mechanism

2. Installation

2.1 server side:

# Yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

# Wgethttp: // git-core.googlecode.com/files/git-1.9.0.tar.gz

# Tar zxvf git-1.9.0.tar.gz

# Cd git-1.9.0

# Make prefix =/usr/local all

# Make prefix =/usr/local install # Run as the root user

View the version: git -- version

Git version 1.9.0

Install gitosis: gitosis is a Git user permission management system. It manages user permissions by managing the/home/git/. ssh/authorized_key file on the server. It is a python module package.

# Yum install python-setuptools

# Git clone git: // github.com/res0nat0r/gitosis.git

# Cd gitosis/

# Python setup. py install

If Finished processing dependencies for gitosis = 0.2 is displayed, the request is successful.

2.2 Client installation:

# Yum install git

# Git -- version

Git version 1.7.1

3. ssh settings

The client generates the key and uploads it to the server:

# Ssh-keygen-t rsa

# Scp ~ /. Ssh/id_rsa.pub root@192.168.56.1 :~ /

Check the uploaded key on the server: ls ~ /Id_rsa.pub

4. Generate git users on the server, use git users, and initialize gitosis

Add User git:

# Useradd-r-s/bin/sh-c 'git version control'-d/home/git

Set permissions:

# Mkdir-p/home/git

# Chown git: git/home/git

Generate a management database on the server:

# Sudo-H-u git gitosis-init <~ /Id_rsa.pub

Initialized empty Git repository in/home/git // repositories/gitosis-admin.git/Reinitialized existing Git repository in/home/git/repositories/gitosis-admin.git/

Note:

1. The generated gitosis-admin is the Git user access permission management library. gitosis manages the access permissions of all git libraries through this git library.

2. After initialization, the owner of the public key can modify the special Git repository used to configure gitosis.

Modify the upload permission:

# Chmod 755/home/git/repositories/gitosis-admin.git/hooks/post-update


5. CLIENT Export Management

# Mkdir-p/git-repo/

# Cd/git-repo/

# Git clone git@192.168.56.1: gitosis-admin.git

# Cd gitosis-admin

# Find.

./gitosis.conf

./keydir

./keydir/oot@vm1.pub

Note:

gitosis.confControl file used to set users, warehouses, and permissions

The keydir directory stores all the places with the public key of the user with access permissions.

./Keydir/root@vm1.pub: As described earlier, the user has access

6. Create and set a management project on the client

# Cd/git-repo/gitosis-admin

View uploaded keys

# Ls keydir/

Root@vm1.pub

Authorization and permission Control

# Vim gitosis. conf

[Gitosis]

[Group gitosis-admin]
Writable = gitosis-admin
Members = root @ vm1 # Show the user root@vm1.pub is the owner of the initialized gitosis public key and the only one who can manage the gitosis-admin Project

[Group jay_fans] # group name
Members = root @ vm1 # key Username
Writable = git-test # project name

7. Initially, add and use the project git-test

# Cd/git-repo

# Mkdir git-test

# Cd git-test

# Git init

# Touch README

# Git add.

# Git commit-a-m "init git-test"

# Git remote add origin git@192.168.56.1: git-test.git

# Git push origin master

Note: Before pushing data to the server for the first time in the new project git-test, you must set the server address as a remote repository, however, you do not need to manually create the bare repository of the project on the server beforehand-Gitosis will be automatically created when the first push is encountered.

8. Add other member public keys on the client to the system: add the user's public key to the keydir directory.

# Cd/git-repo/gitosis-admin

# Cp/path/to/member/public/key keydir/

# Git add keydir/member. pub

Modify gitosis. conf

[Group jay_fans] # group name
Members = jay # New Key Username
Writable = git-test

Submit changes:

# Git commit-a-m "granted jay commit rights to git-test"

# Git push

Note: gitosis is actually a slave server/home/git /. gitosis. if the conf file reads information, the new permission information will be written to the file through the above operations. If the configuration is incorrect, the push permission will be lost, you can modify the file to reset it. If you manually edit the file, it will be maintained until the next timegitosis-adminPush the configuration content of the new version.

Run the following command to obtain the Code:

# Git clone git@192.168.56.1: git-test.git

4. Use of Github

GitHub is a website hosting Git projects. It charges fees for closed-source projects, while open-source projects are free of charge. The steps for code release and hosting using Github are as follows:

1. log on to the Github official website https://github.com/, apply for a githubaccount, and create a repository named github-test

2. Install the Git client (Linux)

# Yum install git-gui

3. Generate a key pair and copy it to the Github website.

# Ssh-keygen-t rsa-C "xxx@gmail.com"

Xxx@gmail.com is the email account you registered for Github

Log on to Github and click Edit your profile-> SSH keys to add content in./. ssh/id_rsa.pub.

4. Set ssh without entering a password

# Eval 'ssh-agent'

# Ssh-add

5. Test whether GIthub can be connected.

# Ssh git@github.com

PTY allocation request failed on channel 0
Hi rangochan! You 've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

Connection successful

6. Configure Git global user configuration

# Git config -- global user. name xxx

# Git config -- global user. email xxx@gmail.com

Xxx and xxx@gmail.com are Github account names and mailboxes respectively

7. Create a local project

# Mkdir github-test

# Cd github-test/

# Git init

# Touch README

# Git add README

# Git commit-m' my first commit'

Define Remote Server alias origin

# Git remote add origin git@github.com: xxx/github-test.git

Merge local and remote operations. The local default is master.

# Git push origin master

When Github uses xxx to modify github-test, the following error occurs because the local snapshot is inconsistent with that on the remote server of Github:

! [Rejected] master-> master (fetch first)
Error: failed to push some refs to 'git @ github.com: xxx/puppet'
Hint: Updates were rejected because the remote contains work that you do
Hint: not have locally. This is usually caused by another repository pushing
Hint: to the same ref. You may be want to first integrate the remote changes
Hint: (e.g., 'git pull... ') before pushing again.
Hint: See the 'note about fast-forwards 'in 'git push -- help' for details.

Solution:

Update the changes made in the Github project using the pull sub-command.

# Git pull origin master

Then execute git push origin master.

Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 714 bytes | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)

Log on to https://github.com/xxx/github-testto Go To The github-testproject.

8. Update files

# Vim README

Just for test

Automatic commit to change files

# Git commit-

Update to remote

# Git push origin master

9. Create and merge branches

# Git branch

* Master

Displays that the current branch is a master node.


# Git branch new-branch

Create Branch


# Git checkout new-branch

Switch to new branch


# Vi check. py

Create a new file

# Git add check. py
# Git commit-a-m "added a python script"

Commit to local Git


# Git push origin new-feature
Merge to remote server

If the new-branch is mature, it can be merged into the master
# Git checkout master


# Git merge new-branch


# Git branch

* Master
New-banch

# Git push
Execute merge. Updates in new-branch are also merged in master.

Log on to GitHub and click "Switch Branches" to change the branch to view the code of different Branches.

-- Rango Chen

This article from the "game cloud stop" blog, please be sure to keep this source http://rangochen.blog.51cto.com/2445286/1394340

Related Article

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.