User Tools

Site Tools


linux:install_gitolite

This is an old revision of the document!


Install Gitolite

This page shows how to setup a git/gitolite server and how to setup your workstation to work with the git/gitolite server.

Gitolite is a tool which allows for easy configuration of who can access projects and what permissions they have over an SSH connection.

In order to allow connections over SSH and public/private key combination is required. Gitolite uses this public key on the server side to restrict the access. For this reason, all members of the IT department who use Git are required to create one of these keys for each machine they use.

Prerequisites

For the server, you must have a CentOS machine already set up in accordance with the Install CentOS 6 guide.

For the workstation, you must have Windows 7.

Install Git on Workstation

You need to install Git on your workstation. The only server that has Gitolite installed is the server. Workstations just need Git. You can download it here.

Accept the license and most of the defaults. Double check to ensure that the following are selected when they come up.

  • Run GIT and included Unix tools from the Windows command prompt
  • Use OpenSSH
  • Checkout Windows-style, Commit Unix-style line endings

That is all you have to do.

Creating an SSH Key

Once Git is installed, you need to generate a public key and a private key. The public key will end up on the Gitolite server. The private key stays on your workstation.

  • Open a command prompt (Start > Run > cmd)
  • Ensure your prompt is C: and not something else (e.g. J:)
    c:
  • Move to your user folder (e.g. C:\users\bstafford)
    cd c:\users\username
  • Generate the keys. Choose all default options (including setting the passphrase to empty)
    ssh-keygen -t rsa
  • The public key created (usually called id_rsa.pub) must now be placed in to the gitolite-admin git repository on the server. A current admin of the Git server has to do this.Admin rights to this project are required, hence if this is the first machine you are setting this up on you will need to send the .pub file to Ben or Calvin.

If using Spingsource or Gitgui, the repository to use is ssh:git@gitbox:gitolite-admin.

The admin should copy the id_rsa.pub file to C:\Git\gitolite-admin\keydir on his machine and rename it username.pub (e.g. bstafford.pub). He should then push it to the server.

Open the command prompt and change to C:\Git\gitolite-admin\

git add .
git commit
  - You will be put into a vim editor. Type out a description of the change and then save and quit with :wq
git push

The admin should follow the “Adding Users” section below.

Adding Users

If using Spingsource or Gitgui, the repository to use is 'ssh:git@gitbox:gitolite-admin'. Edit C:\Git\gitolite-admin\conf\gitolite.conf. It should be fairly self-explanatory what needs to be done to add users to repositorys. To add the user as an admin, add them to the gitolite-admin repository. Open the command prompt and change to C:\Git\gitolite-admin\ <code>git add . git commit - You will be put into a vim editor. Type out a description of the change and then save and quit with :wq git push</code> i.e. * When a user has the public key correctly in the keydir, in order for their access to be controlled to specific projects, Gitolite provides the gitolite.conf file (again in the gitolite-admin project). * To add a user to an existing project, simply put there name (i.e. the name of the .pub file without the extension) in the space separated list of other users of that project with the appropriate permissions, i.e. R for read-only, RW for read-write, RW+ for full control. * To add a new user for gitolite-admin add them to the members of the gitolite-admin repo. * After making changes, do not forget to commit and push to the server. =====Adding Projects===== Important - You should 'never' add a project directly to the server. This circumvents gitolite. Always use the method described here: * Add a new repo section to the gitolite.conf file (in gitolite-admin project). * Commit and push, this will create the repository. * Clone that repository (git clone git@gitbox:<name of repo>.) * Run the following from a command line - * * git commit –allow-empty * * git push origin master * Delete and re-clone the repository * Use that repository as normal, i.d. add your files and push as you would normally. =====Moving an existing Repository===== For an already created repository do the following: * Create the bare repository in gitolite (using the method above) * Go to the repository to move on your machine and run the following commands: * git push –all git@gitbox:<name of gitolite repo> * git push –tags git@gitbox:<name of gitolite repo>'' After this you can then pull the new repository and use it as before, all history should be available. =====Sync Repository to Workstation===== * Open command prompt and change to C:\Git * Substitute REPO for the name of the repository (e.g. gitolite-admin)<code>git clone git@gitbox:REPO</code> =====Creating a new Branch===== ====Using STS==== - From Git Repositories view, select 'Switch To' → 'New Branch' - Ensure Source Ref is the branch the new branch will branch from - Enter branch name (lowercase) New branch is created - 'Push' to remote, updating and saving Push Ref Specifications - 'Pull' If error shows that the current branch is not configured for Pull - Open configuration by Window → Prefernces → Team → Git → Configuration → Repository Settings - Check / update remote and merge keys for branch i.e. - * branch.<branchName>.remote = origin - * branch.<branchName>.merge = refs/heads/<branchName> ====Using Git Gui==== - Create New Branch - Remote → Push… which will create new remote branch In STS, ensure Pull is OK, if not configure as above =====Install Git and Gitolite On New Server===== - Run the following as root<code>yum -y install git* perl-Time-HiRes</code> - Create a new user called git but don't set any password<code>adduser git</code> - Change to git user<code>su - git</code> - Clone the gitolite repo with git<code>git clone git:github.com/sitaramc/gitolite</code> - Make directory /home/git/bin <code>mkdir $HOME/bin</code> - Copy public ssh key of an administrator (e.g. Ben, Calvin, etc) from workstation to server and put in $HOME, i.e. /home/git/cthomas.pub - Run<code>gitolite/install -to $HOME/bin</code> - Run<code>gitolite setup -pk <pub file>, i.e. gitolite setup -pk cthomas.pub</code> =====Test Basic Setup===== To ensure the above has worked correctly do the following from the workstation the pubkey was created from (the private key should be in J:\.ssh) <code>git clone git@SERVERNAME:gitolite-admin</code> If all is well this will clone successfully. =====Move repositories===== - Copy the repositories directory from the old server to the new server and put in a temporary directory, i.e. /tmp. Usually these will be in /home/git/repositories. From the old server run<code>scp -r /home/git/repositories git@<new server>:/tmp</code> - As root on the new server set the ownership of the new repositories to git <code>chown -R git:git /tmp/repositories</code> - As git user, copy all repositories from within the temporary directory to $HOME/repositories<code>cp -R /tmp/repositories /data/git/repositories</code> - <code>cd $HOME</code> - <code>ln -s /data/git/repositories repositories</code> - Run the following replacing ADMINNAME with something like bstafford or cthomas. This will overwrite the gitolite-admin project.<code>gitolite setup -pk ADMINNAME.pub</code> - On your workstation, clone the old gitolite-admin repositories on the workstation<code>git clone git@<OLDserver>:gitolite-admin</code>. These will need to be in separate directories. - On your workstation, clone the new gitolite-admin repositories on the workstation. NOTE: this will need to be in a separate directory from the one used to store files from the old server.<code>git clone git@<NEWserver>:gitolite-admin</code> - Overwrite the conf and keydir of the new repository with the old. To do this, just copy conf and keydir from OLD_GIT_DIR/gitolite-admin on your workstation to NEW_GIT_DIR/gitolite-admin on your new workstation. - Add any new files<code>git add .</code> - Commit in the new repository<code>git commit</code> - Push the new repository<code>git push</code> You should now be able to clone all of the other repositories as required and all users should have access. =Backup= Ensure that the backup dir on file3 is mounted to /backup/git on the git server and that the user git can read and write to it. You will need the following /backup/git/backupGit.sh <code>echo “Starting repository archive” cd /data/git tar -zcvf git_repositories_backup.tar.gz repositories mv -f git_repositories_backup.tar.gz /backup/git echo “Finished repository archive” exit 0</code> And add the following to crontab as the user 'git' <code>crontab -e - Backup redmine every night. 15 * * * * cd /backup/git; ./backupGit.sh</code>

linux/install_gitolite.1590396143.txt.gz · Last modified: (external edit)