Support / KnowledgeBase

 
Search the KnowledgeBase Search

Using Git

  • Applies to: (gs)

  • Difficulty: Hard

  • Time needed: 30 minutes

  • Tools needed: ssh, vi

 

Git is an open-source version control system designed to handle very large projects with speed and efficiency.

Git falls in the category of distributed source code management tools, similar to CVS, Subversion (svn), or Bazaar. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Still, Git stays extremely fast and space efficient.

This article will focus on using Git with a subdomain on your (gs) Grid-Service.

This article has the following dependencies:


  • Whenever installing Third-Party software please consult the official documentation. (mt) Media Temple does not support the installation and configuration of software not installed at time of service activation. Please consult our (gs) Scope of Support page for further explanation.
  • mt-example.com is used as an example. Please be sure to replace this text with the proper information for your site or server.
  • This article assumes that you have already set up git locally on your own computer. Due to the diversity of desktop computer platforms, this article does not cover the steps to get it set up locally.
  •  

    The following Git packages are installed on the (gs) Grid-Service:

    • git-core
    • git-doc
    • git-email
    • gitweb
    • git-svn

    These packages provide core Git functionality as well as the ability to browse repository information on the web and bridge Git with Subversion.

    The current installed version of Git is 1.5.4.1.

    Creating a repository for use on your (gs) subdomain

    The normal workflow when using Git is saving your work to a local repository on your personal computer and, when ready for publishing, "pushing" those changes to your "bare" repository.  Here are the steps needed for this process.

    1. Add an alternate or subdomain to your service through the AccountCenter.  For this article we will use the descriptive name 'git.mt-example.com'.
    2. On your personal computer make a directory and create your bare repository:

    NOTE:

    Remember that this article assumes your are using a Unix environment, such as OS X, on your personal computer.  If you are using Windows please substitute the usage of the following commands to match your local environment.


    mkdir mt-example && cd mt-example
    git init
    
    

    3. Now create a meaningless test file that we will commit to the local repository:

    touch .gitignore
    git add .gitignore
    git commit -m "just adding test gitignore file"
    

    4. Create the "bare" clone named mt-example.git:

    Before we can push our local Git repository to the Grid we have to create a bare clone.  A default git repository assumes that you’ll be using it as your working directory, so git stores the actual bare repository files in a .git directory alongside all the project files. Remote repositories do not need copies of the files on the filesystem unlike working copies. This is what “bare” means to git -- just the repository itself.

    cd ..
    git clone --bare mt-example mt-example.git
    touch mt-example.git/git-daemon-export-ok
    
    
    

    5. It's now time to upload the repository to your (gs) Grid-Service using scp.  Please make sure ssh is enabled in the AccountCenter:

    scp -r mt-example.git serveradmin%mt-example.com@mt-example.com:domains/git.mt-example.com/html/mt-example.git
    
    

    6. Login to your (gs) to complete the setup using ssh:

    ssh serveradmin%mt-example.com@serveradmin@mt-example.com
    cd domains/git.mt-example.com/html/mt-example.git
    git --bare update-server-info
    cd hooks
    mv post-update.sample post-update
    chmod a+x post-update
    

    Your repository is now configured!!  At this point you and your contributors will now be able to push and pull content to your new repository.

    Using your repository:

    Pulling

    New users can clone your repository directly from the Grid using http with the following command:

    git clone http://git.mt-example.com/mt-example.git
    

    Pushing

    Now that we have a working repository both locally and on the Grid we can start using git to "push" new content.  Assuming you have added/updated new files locally you would use the following command to update your repository on the Grid from within your local mt-example directory:

    git push ssh://serveradmin%mt-example.com@mt-example.com/home/#####/domains/git.mt-example.com/html/mt-example.git master 

    Of course that is quite a lengthy command to use every time you want to push your files.  You can actually create a shortcut for the above using the git remote add function.  The following command matches up to the one above and uses the word grid as the shortcut name.  Make sure you are in your local mt-example directory first before running this command:

    git remote add grid ssh://serveradmin%mt-example.com@mt-example.com/home/#####/domains/git.mt-example.com/html/mt-example.git 

    Now you can simply push using the command:

     git push grid master
    For more information about public Git repositories, see this page in the Git user manual.

    (Optional) Using gitweb

    Gitweb is a CGI application that allows anyone to browse the history and content of your repository using a web browser.  If you would like to use this please follow the directions below.  You might also want to consider password-protecting this url.

    1. Login to your (gs) Grid-Service using ssh and navigate to the cgi-bin directory for git.mt-example.com.

    ssh serveradmin%mt-example.com@mt-example.com
    cd domains/git.mt-example.com/cgi-bin 

    2. Create a new cgi script named gitweb.cgi in the cgi-bin directory with the following contents.  Ensure that your path is correct:

    #!/usr/bin/perl
    $ENV{'GITWEB_CONFIG'} = '/home/#####/domains/mt-example.com/gitweb.conf';
    exec '/usr/lib/cgi-bin/gitweb.cgi'; 

    3.  Make this script executable using the chmod command:

    chmod +x gitweb.cgi 

    4. Copy the default configuration file from the server:

    cd ..
    cp /etc/gitweb.conf gitweb.conf 

    5. Edit this gitweb.conf file.  The only required variable needed to be changed is $projectroot:

    $projectroot = "/home/#####/domains/git.mt-example.com/html"; 

    6. Copy over the static resources from our server:

    cd html
    wget http://s1.gridserver.com/git/git-favicon.png
    wget http://s1.gridserver.com/git/git-logo.png  
    wget http://s1.gridserver.com/git/gitweb.css   

    7. In your web browser visit http://git.mt-example.com/cgi-bin/gitweb.cgi to view the interface and you should see your repository on the web!! 

    NOTE:

    If your repository description is "Unnamed repository; edit this file to name it for gitweb.", edit the description file in the base of your repository at mt-example.git/description:


    For more information, see the INSTALL documentation for gitweb.

    Notes/Supplemental Resources:

    Revisions:


    01-02-2008: Major rewrite of our first git article published in June 2008.

    User Comments

    No visitor comments posted. Post a comment

    Fields marked with an asterisk(*) are required. Comment on this article

    Fill out the form below if you would like to comment on this article.
     
     
     

    (code is not case-sensitive)
     
    Submit
     
     

    Continue