Join Jon Peck for an in-depth discussion in this video Hosting Git repositories with gitolite, part of Up and Running with Linux for PHP Developers.
Installation of gitolite requires a number of steps beyond the base software and installation. Lets start by connecting the SSH to our development environment and install the required packages. We can just use sudo app-get -y for yes. Install git and gitolite. It'll ask me for my password, and Ubuntu will install the packages. Now that the software's been installed, let's create the user that GitLite will be running as.
This user will have a shell, which will allow Git to work, but will not be able to log in. So we'll use sudo adduser --system. We'll give it a shell. --shell /bin/bash --gecos. This be a label so, 'Git SCM' --group --disabled-password, and then finally, the name of the user, git. So we can actually manage the gitolite hosting.
We'll need to create a public private keypair for our Linux user. So ssh-keygen -t rsa. We can just press Enter to all these questions. No passphrase is needed. And the key is generated. The next step is to put the public key in a place where it can be read by the Gitolite setup. The temporary directory, temp, is accessible throughout the entire system. So, I'm going to use cp to copy the .ssh file from my home directory, id_rsa.pub.
And we'll copy it to /tmp/local.pub. Let's run the gitolite setup script. sudo -Hu git gl-setup, and we'll specify the location of that key. So, /tmp/local.pub. Press Enter and lets use the default editor which is Nano. Lets go down and look for web interface. Lets uncomment that. Gitweb is fine. Gitweb URI escape lets set to one.
And the repo u mask set to zero, zero, seven. Finally, search for GITCONFIG_KEYS. And we'll set it to the following pattern: gitweb\.owner pipe description pipe category. Close the parentheses and add an asterisk. This will allow us to add metadata to the repositories for GitWeb to read. Press Ctrl+X to exit, and Y to save. Press enter and the program's been initialized.
Clean up by removing the copy of the public key from the temporary directory. So, rm, space, slash, temp, local, dot, pub. Getalight is installed, but is completely default. Let's learn how to configure it. To start, we're going to have to set up our git user. Every commit is associated with a name and email, and we'll need to specify that. First, start out by specifying your name. We'll use git config --global. And we'll set the user.name, my name is Jon Peck.
Then specify your email address. Git config dash dash global email@example.com. Now that git's configured let's clone, meaning get a full copy of the git repository that stores the git alike configuration. So, CD space tilde then git clone. git@localhost:gitolite-admin.git. This is the special repository that actually stores the configuration for gitolite.
Make sure, you wish to continue connecting. Yes. This will create a local copy of the project in a directory named after the project. Change directory to the gitolite-admin directory. What's in here? Perform a directory listing. Three directories exist. Conf, which stores the configuration, .git which is the metadata for the repository, and keydir which stores the public keys for users who can access the repository. Let's add the credentials of the host machine's user so we can access the repositories. Part of our setup is copying the public key to authorized keys, so let's just copy that right out and into the keydir.
Name the file after the username, which is in my case is jpeg. So I will cat, from my home folder ~/.ssh/authorized_keys, and we'll send that to keydir/jpeck.pub. Now that we've added the credentials for the user, let's update the configuration to add repositories and the user. The configuration is stored in the conf directory in a file called gitolite.conf. So just nano, space, conf/gitolite.conf. Two repositories are ready in here. Gitolite-admin and testing.
Let's add one starting with a repository for the dash board. The syntax is straight forward. Start with the word, repo, followed by a tab, and the nane of the repository. In this case, dashboard. On the next line, indent by a tab, and rw plus for rewrite, tab equals tab, and then the user name, jpack. When complete, press control x to exit, and y to save and enter Let's see what changes have been made using the Git, div command. The changes the configuration found, but not the new file.
Git status on the other hand, shows that both the Git or like configuration file was modified, but we've also added a new file, the keyder.//jpeck.pub. That is untracked. Lets prepare all the files for our committing by staging them all. git add space -A, then we can commit the change with a descriptive message. git commit space dash m Added new user comma dashboard repository. Close the double quote and press enter.
Finally, we'll send the changes to gitolite which will automatically reconfigure itself based on the contents they commit. So, git push origin master. You want to see a history of the repository, we can use that git log command. Whatever, this is pretty bare bones, we can get a much better perspective if we use a graphical user interface. So lets install one.
The demonstrations are performed with the Ubuntu LTS distribution of Linux, but the skills taught here are also applicable to other Linux distributions. Every command is described in detail in context, and a comprehensive quick reference is provided for convenience.
- What is Linux, and why should I use it?
- What's a LAMP, and why does it matter?
- Creating and configuring a virtual machine
- Working with the Linux command line
- Configuring the servers, including Apache virtual hosts
- Building a development server dashboard
- Using PHP package managers like Composer and PEAR
- Installing Drupal, WordPress, and more on the server
- Self-hosting Git repositories, including a web interface
- Enhancing the server with debugging and profiling
- Exporting a virtual appliance to use on another machine
- Server troubleshooting techniques