3 Git Server Setup

Source: Internet
Author: User
Tags hosting email account git client

1. Environment deployment

System environment: Server side: CentOS 6.5, ip:192.168.56.1

Client: CentOS 6.5, ip:192.168.56.101

Software version: Server-side: source code compiled and installed, 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

#wget http://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 #root用户运行

View version number: Git--version

git version 1.9.0

Install Gitosis:gitosis as a GIT user Rights management system, manage the user rights by managing the/home/git/.ssh/authorized_key file on the server, is a Python module package

#yum Install Python Python-setuptools

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

#cd gitosis/

#python setup.py Install

Show finished processing dependencies for gitosis==0.2 is successful

2.2 Client Installation:

#yum Install git

#git--version

git version 1.7.1

3. SSH settings

The client produces the key and uploads it to the server side:

#ssh-keygen-t RSA

#scp ~/.ssh/id_rsa.pub [Email protected]:~/

Service side view the key that has been uploaded: LS ~/id_rsa.pub

4. Generate GIT users on the server, use git user and initialize Gitosis

Add user git:

#useradd-R-s/bin/sh-c ' git version control '-d/home/git git

Set permissions:

#mkdir-P/home/git

#chown Git:git/home/git

To build the management library on the server side:

#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/

Annotations:

1. The generated gitosis-admin is a git user access management library that gitosis through this git repository to manage access to all git libraries.

2. By performing the initialization, the owner of the public key can modify the particular git repository used to configure the gitosis.

To modify upload permissions:

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


5. Client Export Management

#mkdir-P/git-repo/

#cd/git-repo/

#git Clone [Email protected]:gitosis-admin.git

#cd Gitosis-admin

#find.

./gitosis.conf

./keydir

./keydir/[email protected]

Annotations:

gitosis.confFiles used to set up control files for users, warehouses, and permissions

The Keydir directory is where all the public keys of the user with access rights are saved

./keydir/[email protected]:如前所述,该用户具有访问权限

6. Client creation and Setup management project

#cd/git-repo/gitosis-admin

View already uploaded keys

#ls keydir/

[Email protected]

Authorization and permission control

#vim gitosis.conf

[Gitosis]

[Group Gitosis-admin]
writable = Gitosis-admin
Members = [email protected] #显示用户 [email protected] is the owner of the initialized Gitosis public key and is the only person who can manage the Gitosis-admin project

[Group Jay_fans] #组名称
Members = [email protected] #密钥用户名
writable = Git-test #项目名称

7. Initial, increase and use of 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 [email protected]:git-test.git

#git Push Origin Master

Note: In the new project Git-test first push data to the server, you need to set the server address as a remote warehouse, but you do not have to manually create the project to the server bare warehouse-gitosis will be automatically created when the first time you encounter a push.

8. The client adds the other member's public key to the system: by adding 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] #组名称
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/home/git/from the server side. gitosis.conf file read information, through the above operation, the new permission information will be written to the file, if the wrong configuration, resulting in the loss of push permissions, you can modify the file to re-set, if you manually edit the file, it will remain until the next gitosis-admin Pushes the new version of the configuration content up to date.

Member Jay gets the code by using the following command:

#git Clone [Email protected]:git-test.git

4 Use of GitHub

GitHub is a Web site hosting a git project that charges for closed source projects and is free for open source projects. The steps for code publishing and hosting using GitHub are as follows:

1. Log on to the GitHub website https://github.com/, request a GitHub account, and create a repository named Github-test

2. Install the GIT client (Linux)

#yum Install git Git-gui

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

#ssh-keygen-t rsa-c "[Email protected]"

[Email protected] for your email account when you sign up for GitHub

Login to GitHub Click Edit your profile->ssh keys to add the contents of the./.ssh/id_rsa.pub

4. Set SSH to not enter a password

#eval ' Ssh-agent '

#ssh-add

5. Test if you can connect to GitHub

#ssh [email protected]

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 [email protected]

XXX and [email protected] are GitHub account names and email addresses respectively

7. Create a new local project

#mkdir Github-test

#cd github-test/

#git Init

#touch README

#git Add README

#git commit-m ' My first commit '

To define a remote server alias origin

#git remote Add origin [email protected]:xxx/github-test.git

Local and remote merge, local default is master

#git Push Origin Master

When making changes to github-test via github with XXX, due to inconsistencies on the local snapshot and the GitHub remote server, the following error is caused:

! [Rejected] Master--master (fetch first)
Error:failed to push some refs to ' [email Protected]:xxx/puppet '
Hint:updates were rejected because the remote contains work the
Hint:not has locally. This was usually caused by another repository pushing
Hint:to the same ref. Want to first integrate the remote changes
Hint: (e.g., ' git pull ... ') before pushing again.
Hint:see the ' Note about Fast-forwards ' "Git push--help ' for details.

Solve:

Update the changes made in the GitHub project with the PULL subcommand

#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)

Login to Https://github.com/xxx/github-test to view Github-test project

8. Update files

#vim README

Just for Test

Automatic commit Change file

#git commit-a

Update to remote

#git Push Origin Master

9. Create and Merge Branches

#git Branch

* Master

Show that the current branch is master


#git Branch New-branch

Create a branch


# git checkout New-branch

Switch to a 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
Merging to a remote server

If the New-branch branch matures, you can merge into Master
#git Checkout Master


#git Merge New-branch


#git Branch

* Master
New-banch

#git push
Perform the merge, and the update in New-branch is also merged in master

Log on to GitHub and click "Switch Branches" to change the branch to see the code under different branches.

3 Git Server Setup

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.