Monday, October 3, 2011

Simply Set up Git on Apache

I actually referred to this blog page "8 ways to share your git repository".
I am using Linux as server. On my personal computer with Microsoft Windows I have installed [Git For Windows] and [Git Extentions] as client.
  1. It's really useful later to make the parent directory which holds all your git repositories. It can be used by 'gitweb'. On the server, make it and let's call it 'GitRepos' here.
    $ mkdir GitRepos
    $ chown -R apache:apache GitRepos

  2. Under the parent directory, make a git repository.
    $ cd GitRepos
    $ mkdir ProjectX
    $ cd ProjectX
    $ git --bare init
    Initialized empty Git repository in /GitRepos/ProjectX
    $ chown -R apache:apache .
    $ sudo -u apache git update-server-info

  3. I recommend using a virtual host solely for git because of useful 'gitweb' later on. Assign a dedicated subdomain such as 'git.mydomain.com' to it. To begin with, in '/etc/httpd/conf' directory, open 'httpd.conf', find 'Include conf.d/*.conf', type in 'NameVirtualHost *:80' at the line just before the found line.
    #
    # Load config files from the config directory "/etc/httpd/conf.d".
    #
    NameVirtualHost *:80
    Include conf.d/*.conf
    
    Search for the next same line as you have typed in and remove it so that the first one is unique.

  4. In '/etc/httpd/conf.d' directory, create or open 'git.conf' and add a virtual host as following.
    <VirtualHost *:80>
        ServerName git.mydomain.com
        Alias /ProjectX /GitRepos/ProjectX
        <Directory /GitRepos/ProjectX>
            DAV On
            Options +Indexes +FollowSymLinks 
            AllowOverride None
            Allow from all
            Order allow,deny
        </Directory>
    </VirtualHost>
    Note: Make sure that the alias doesn't overlap path names under subversion WebDAV. If so, you get the apache error "A subtree cannot specify a different DAV provider than its parent."(/var/log/httpd/error_log) and keep being asked to log in to fail.

    Restart the web server
    $ service httpd restart
    Stopping httpd:                                      [  OK  ]
    Starting httpd:                                      [  OK  ]
    
    Point your web browser to 'http://git.mydomain.com/ProjectX' and check if the physical git repository is shown as files and directories.

  5. On your PC, run "Git Extentions" and under "Common Actions" in the upperleft corner of the main window, choose "Create new repository", the last item.
    Put in a new path to ProjectX_Origin folder which I remcommend you delete later after setting up, choose "personal repository", and then click Initialize button.

  6. On the menu, choose Settings-Settings. The dialogbox pops up.
    Choose "Local Settings" tab, put "originator" into "User Name" and click Ok button. .

  7. Click "Edit .gitignore" button in the main window. The dialogbox pops up.
    Click "Add default ignores" button and then Save button.

  8. Click Commit button in the main window. The dialogbox pops up.
    Click ".gitignore" file, click Stage button, type in a comment like "added .gitignore.", and then click Commit button.

  9. On the menu, choose Remotes-"Manage remote repositories", "Remote repositories" dialogbox pops up.
    On "Remote repositories" tab, fill in Name editbox with "ProjectX" and type URL address "http://git.mydomain.com/ProjectX" into Url. and then click Save button. The following dialogbox pups up.
    Click Yes button, and then close the "Remote repositories" dialogbox.

  10. On the toolbar, click the push button which is marked by a red rectangle. The dialogbox pops up.
    Choose the remote name that you just made earlier from the dropdown list and then click Push button. The following dialog pops up.
    Click Yes button.
    Now the original initial repository got pushed into the server and everyone can share it.
    I recommend deleting the original local repository and cloning the remote repository for your own workspace.

  11. After cloning your own local workspace, choose menu "Settings-Settings" to pop up the dialogbox, Choose "Local settings" tab and then the third "Line endings" option "Checkout as-is, commit as-is".