Install msysgit + Apache-Git Server

Source: Internet
Author: User

Above we have installed msysgit and Apache separately, and now we can configure the GIT server.

1. Create the test. Git Library

To verify that the installation is correct, you must first create a git library and then access it through http. The GIT library itself can be used independently and does not necessarily require access through http: //. Local access can be performed using file: //, but through http: // remote access is allowed.

Note: The local and remote access mentioned here may be somewhat misleading. For git, whether the two libraries are on the same machine or not, accessing one library from another is called remote access.

When integrating with Apache, you need to put all the GIT Libraries under a root directory. Here I select E:/Git-parent/as the root. You can also select another directory as the root, but you should pay attention to modifying the root directory as your own.

Next we will create a database named test. Git under the root directory. You can create a git repository using any of your favorite tools, such as tortoisegit. However, the git-bash command is more straightforward.

Next we will use Git-bash for operations.

 $ Mkdir/e/Git-parent
$ CD/e/Git-parent $ mkdir test. Git $ CD test. Git $ Git init -- Bareinitialized empty git Repository In E:/Git-parent/test. Git/

$ Ls - Ltotal 2 -RW-r -- 1 Yangwu administ 23 Oct 5 00 : 26 Head -RW-r -- 1 Yangwu administ 131 Oct 5 00 :26 Config -RW-r -- 1 Yangwu administ 73 Oct 5 00 : 26 Descriptiondrwxr -XR-x 1 Yangwu administ 0 Oct 5 00 : 26 Hooksdrwxr -XR-x1 Yangwu administ 0 Oct 5 00 : 26 Infodrwxr -XR-x 1 Yangwu administ 0 Oct 5 00 : 26 Objectsdrwxr -XR-x 1 Yangwu administ 0 Oct5 00 : 26 Refs

The GIT library is actually a directory with some git system files. Note: There are two git libraries. As shown above, we have created a git library in the bare format, which cannot be placed into the files we work on. Another form is to hide the sub-directory library with. Git. This library can be put into the workComposition(Git is called the work tree and working tree). Of course, the work file is not stored in the. Git hidden subdirectory. Create a git library in the form of bare on the server.

The test. Git library is created above. To clone this library, perform the following operations:

$ Git clone file: ///  E:/Git-parent/test. Git Cloning '  Test  '  ... Remote: counting objects:  15 , Done. Remote: compressing objects:  100 % ( 9 / 9  ), Done. Remote: Total  15 (Delta 2 ), Reused 0 (Delta 0  ) Permission ing objects:  100 % ( 15 / 15  ), Done. Resolving deltas: 100 % ( 2 / 2 ), Done.

You can also use the Windows syntax to write:

 
$ Git clone E: \ Git-parent \ test. Git

The results are the same. However, the purpose of this article is to use the following HTTP syntax to access:

 
$ Git clone http://Localhost/test. Git

To support using HTTP to access the GIT library, we can install and set Apache HTTP server.

Ii. Set Apache HTTP Server

By default, the installation directory of Apache is

 
C: \ Program Files \ Apache Software Foundation \ apache2.2

To allow us to access the GIT library through http: //, We need to edit the Apache conf \ httpd. conf configuration file.

Add the following at the end of the httpd. conf file:

Setenv git_project_root E:/Git-Parentsetenv git_http_export_all  1  Scriptaliasmatch \  "  (? X) ^/(. */(Head | \ Info/refs | \ Objects /(Info/[^/] + | \[  0 -9a-f] { 2 }/[ 0 -9a-f] { 38 } | \ Pack /Pack -[0 -9a-f] { 40 }. (Pack | idx) | \ Git -(Upload | receive)-pack) $ "  \                          "  C:/program files/git/libexec/Git-core/git-http-backend.exe/$1  " <Directory "  C:/program files/git/libexec/Git-core/  " > Allow  From All </Directory>

To understand these settings, You Need To Know About Apache. If you are interested, refer to http://httpd.apache.org /. But there are several notes:

      • Note the space and 1 at the end of the second line above. Most online tutorials are not added, resulting in running failure. For more information, see http://www.devbean.info/2011/10/apache-git-server-on-windows.

        I think most of the online tutorials are ported from Linux. in Linux, environment variables are allowed only when the variable name has no value, but Windows does not. In this way, you do not need to set it to 1 and set any value. On the other hand, the online tutorial is certainly accessible on the author's machine, probably because the environment variable has been set in the operating system or is related to the following.

      • According to this article, you do not need to define the git_http_export_all environment variable. Instead, create an empty file named Git-Daemon-export-OK in each git library directory, the trouble is that this empty file should be created every time you create a git library, and it is easy to forget.
      • Note that the third line is actually composed of many lines. Do not forget the "\" connector next to it. Some tutorials on the Internet may be caused by web page layout.

After completing the preceding settings, restart the Apache server and check whether it is successfully started. If the task cannot be started successfully, check whether the directory of your root directory and git-http-backend.exe are consistent with the actual situation of your machine, and view Apache logs for more troubleshooting information.

Iii. test and install

To verify the correctness of the above installation, we will perform it in three steps. The first step is to clone test. git library. The second step is to add a new file and push it to test. in the GIT repository, step 3 is from test. git clones another database and checks whether newly added files exist.

1. Create a directory and clone it from the test. Git library.

Next we will still use Git-bash for operations. We will create a new c: \ work directory, and then clone the new test. Git library in the work directory.

 
$ Mkdir/C/Work $ cd/C/Work $ git clone http://Localhost/test. GitCloning'Test'... Warning: You appear to have cloned an empty repository.

The test. Git library is cloned above. Git gave a warning that we cloned an empty library. Ignore this warning. Note that the default port number in httpd. conf is 80. If the port number is not 80, modify the above git clone command.

Next, let's take a look at what the above command has done:

 
$ Pwd
/C/work

$ Ls
Test
$ CD test $ ls-A... git

We can see that the C: \ work \ test directory is created, and there is a. Git hidden directory under this Directory, which indicates that c: \ work \ test is a local library.

2. Add a file and push it to the test. Git library.

In the c: \ work \ testdirectory, create a file named apple.txt and submit it:

 
$ Pwd/C/work/Test $ touch apple.txt $ git add apple.txt $ git commit-M"Added apple.txt"[Master (Root-Commit) 51f3395] added apple.txt1File changed,1Insertion (+) Create Mode100644Apple.txt

Then, we have created an apple.txt file and submitted it to the local database. Next, we push it to the remote test. Git Library:

$ Pwd/C/work/Test $ git push origin mastererror: cannot access URL http://Localhost/test. Git/, return code 22Fatal: Git-http-push failed

An error occurs here. The solution is to edit the E: \ Git-parent \ test. Git \ config file and add two lines:

 
[Http] receivepack=True

Then perform the following operations again:

$ Pwd/C/work/Test $ git push origin masterwriting objects:100% (3/3) Writing objects:100% (3/3),214Bytes, done. Total3(Delta0), Reused0(Delta0) To http://Localhost/test. Git*[NewBranch] Master-> master

Push successful.

3rd, rebuild a database from test.gitand check that there are no apple.txt files that have just been pushed in.

Hosts file.

3. Create another git Library

We created the test. Git library in the root directory. If you need to create another keystore, you can directly create it in the root directory without modifying the httpd. conf file or restarting Apache.

Iv. Authorized access
The preceding configuration uses the anonymous access method. For more information, see this article.

References:

1. http://www.jeremyskinner.co.uk/2010/07/31/hosting-a-git-server-under-apache-on-windows/
Pay attention to three points when configuring according to this tutorial (as mentioned above, let's talk about it again ):
* Add space and 1 after "setenv git_http_export_all.
* The scriptaliasmatch and the following lines must contain the "\" connector.
* Check whether the directory is consistent with the local directory.

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.