Ubuntu perfectly installs and builds a Git Server

Source: Internet
Author: User
Tags git client how to use git
Recently, the company's project needs Git to manage the project. Just over the weekend, it took some time to build a git server in the Ubuntu System of the Virtual Machine. Due to the small problems encountered during the construction process, because my personal memory is not very good, I will record it here for the emergency. I have already installed it once in the Ubuntu12.04 System of the Virtual Machine and forgot to record it. This time, I will build it again in the Ubuntu13.10 System of the virtual machine, later, we will introduce how to install it on a client machine (host machine Win7 ).

Recently, the company's project needs Git to manage the project. Just over the weekend, it took some time to build a git server in the Ubuntu System of the Virtual Machine. Due to the small problems encountered during the construction process, because my personal memory is not very good, I will record it here for the emergency. I have already installed it once in the Ubuntu 12.04 System of the virtual machine. I forgot to record it. This time, I will build it again in the next step of the Ubuntu 13.10 System of the virtual machine, the following describes how to install the git client on the client machine (host machine Win7) and how to use git bash on the client.

1. install the software required by the git Server

Open the terminal and enter the following command:

Ubuntu :~ $ Sudo apt-get install git-core openssh-server openssh-client
Git-core is the core software of git version control.

Install openssh-server and openssh-client because git needs to transmit files between the server and client through the ssh protocol.

Then there is a confirmation operation in the middle. Enter Y and wait for the system to automatically download the software from the backup storage. After installation, the system will return to the user's current directory. If

The installation prompt failed. It may be because the index file of the system software library is too old. Update the file first. The update command is as follows:

Ubuntu :~ $ Sudo apt-get update

After updating the software database index, run the preceding installation command.

Install python's setuptools and gitosis. Because gitosis installation depends on some python tools, we need to install python first.

Setuptools.

Run the following command:

Ubuntu :~ $ Sudo apt-get install python-setuptools
This tool is relatively small and fast to install. Next, we will prepare to install gitosis. Before installing gitosis, We need to initialize the git user information of the server.

Ubuntu :~ $ Git config -- global user. name "myname"
Ubuntu :~ $ Git config -- global user. email "****** @ gmail.com"

After initializing the server user information, you can install gitosis. gitosis is mainly used to grant permissions to users, which is convenient to set permissions.

You can use the following command to obtain the gitosis File

Ubuntu :~ $ Git clone https://github.com/res0nat0r/gitosis.git
Note: There are two numbers in the middle: zero.

After obtaining the gitosis file, go to the file directory

Ubuntu:/tmp $ cd gitosis/

Use the python command to install the python script of setup. py in the directory.

Ubuntu:/tmp/gitosis $ sudo python setup. py install

By now, the entire installation step is complete, and some basic configurations of git are started below.

2. Create a git Administrator Account and configure git

Create an account (git) as the administrator of the git server and manage project permissions of other users.

Ubuntu:/tmp/gitosis $ sudo useradd-m git
Ubuntu:/tmp/gitosis $ sudo passwd git

Create a project repository in the/home directory and set that only git users have all permissions, and other users do not have any permissions.

Ubuntu:/tmp/gitosis $ sudo mkdir/home/gitrepository
Ubuntu:/tmp/gitosis $ sudo chown git: git/home/gitrepository/
Ubuntu:/tmp/gitosis $ sudo chmod 700/home/gitrepository/

Gitosis stores the repository in the user's repositories directory by default. For example, the git user's repository address is in the/home/git/repositories/directory by default, here we need to create a link ing. Let him point to the repository directory/home/gitrepository that we created previously for storing the project.

Ubuntu:/tmp/gitosis $ sudo ln-s/home/gitrepository/home/git/repositories

Here I will generate an ssh public key on the server side. If you want to manage it on another machine, you can also generate an ssh Public Key on another machine.

Ubuntu:/home/git $ ssh-keygen-t rsa

You will be prompted to enter the password. If you do not enter the password, press Enter.

Then, use the generated public key id_rsa.pub to initialize gitosis.

The above information indicates that gitosis has been initialized successfully.

Gitosis mainly manages some configuration files through the gitosis-admin.git repository, such as the management of user permissions. Here we need to add executable permissions to one of the post-update files.

Ubuntu:/home/git $ sudo chmod 755/home/gitrepository/gitosis-admin.git/hooks/post-update

3. Create a project warehouse on the server

Use a git account to create a directory (mytestproject. git) on the server and initialize it as a git project repository.

Ubuntu:/home/git $ su git
$ Cd/home/gitrepository
$ Mkdir mytestproject. git
$ Git init -- bare
$ Exit

If the following information is displayed, a project named mytestproject has been created successfully. the git project repository is created. The new repository is still empty and cannot be cloned by the client. You also need to perform some configuration operations on gitosis.

Iv. Use gitosis to manage user permissions for project operations

First, you need to clone the repository of the gitosis-admin.git on the machine that previously generated the ssh Public Key (used to initialize gitosis.

Create a new directory on the client machine to store the gitosis-admin.git Repository

Ubuntu :~ $ Mkdir gitadmin
Ubuntu :~ $ Cd gitadmin/
Ubuntu :~ /Gitadmin $ git clone git@192.168.1.106: gitosis-admin.git

The following information is displayed when clone is correct.

After cloning, a gitosis. conf configuration file and a keydir directory are generated. Gitosis. conf is used to configure the user's permission information. keydir is used to store the ssh public key file (generally "user name. pub "name, gitosis. the same user name must be used in the conf configuration file.

Now, the user to be authorized can generate the corresponding ssh public key file on their own machines using the previous method. The Administrator will name them separately and copy them to the keydir directory.

Ubuntu :~ $ Cp/home/aaaaa/Desktop/zhangsan. pub/home/aaaaa/gitadmin/gitosis-admin/keydir/

Ubuntu :~ $ Cp/home/aaaaa/Desktop/lisi. pub/home/aaaaa/gitadmin/gitosis-admin/keydir/

Continue to edit the gitosis. conf file

[Gitosis]

[Group gitosis-admin]
#### Administrator Group
Members = charn @ ubuntu
#### Administrator username. You need to find the corresponding. pub file in the keydir directory. Multiple files can be separated by spaces (the same below)
Writable = gitosis-admin #### writable project repository name, separated by spaces (the same below)

[Group testwrite]
#### Writable permission Group
Members = zhangsan #### group users
Writable = mytestproject #### writable project repository name

[Group
Testread] #### read-only permission Group
Members = lisi #### group users
Readonly = mytestproject ### name of the read-only project Repository

Because these configurations are modified locally, they must be pushed to the server to take effect.

Ubuntu :~ /Gitadmin/gitosis-admin $ git add.
Ubuntu :~ /Gitadmin/gitosis-admin $ git commit-am "add a user permission"
Ubuntu :~ /Gitadmin/gitosis-admin $ git push origin master

The following message is displayed when the push is successful.

The new user cannot take effect immediately. In this case, you need to restart the sshd service.

Ubuntu :~ /Gitadmin/gitosis-admin $ sudo/etc/init. d/ssh restart

Now, the server's git has been installed and configured. Next, you need members with permissions to clone the server on their respective machines.

The project warehouse is working properly.

5. Use git on the client (windows)

Download and install the windows version of git client software,: http://msysgit.github.io/

After the installation is complete, right-click the menu and several git-related menu options will appear.
Bash operates through the command line.

Create a local directory, use git to initialize the directory, create a text file for testing, and associate it with the git server repository.

And upload the local version to the server.

$ Mkdir testgit
$ Cd testgit
$ Git init
$ Echo "this is a test text file, will push to server"> hello.txt
$ Git add.
$ Git commit-am "init a base version, add a first file for push to server"
$ Git remote add origin git @ serverip: mytestproject. git
$ Git push origin master

In this way, the server has created a basic version of The mytestproject. git repository. Now, other team members only need to clone the Repository from the server.

Under window, right-click the local directory to be cloned, select the git bash option, and enter

$ Git clone git @ serverip: mytestproject. git

You can clone the project to the local repository.

The following is a simple modification and submission operation:

$ Cd mytestproject
$ Echo "this is another text file created by other"> another.txt
$ Git add.
$ Git commit-am "add a another file by other"
$ Git push origin master

The following information is displayed when the push is successful to the server:

GitHub tutorials:

GitHub tutorials graphic detailed http://www.linuxidc.com/Linux/2014-09/106230.htm

Git tag management details http://www.linuxidc.com/Linux/2014-09/106231.htm

Git branch management details http://www.linuxidc.com/Linux/2014-09/106232.htm

Git remote repository details http://www.linuxidc.com/Linux/2014-09/106233.htm

Git local Repository (Repository) Detailed description http://www.linuxidc.com/Linux/2014-09/106234.htm

Git server setup and Client installation http://www.linuxidc.com/Linux/2014-05/101830.htm

Git overview http://www.linuxidc.com/Linux/2014-05/101829.htm

Share practical GitHub tutorialsHttp://www.linuxidc.com/Linux/2014-04/100556.htm

Git details: Click here
Git: Click here

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-07/120616.htm

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.