Create a git server


Create a git server

  1. apt-get install git
  2. adduser git
  3. Become the git user and add team's ssh keys to /home/git/.ssh/authorized_keys
  4. Change the git user's shell in /etc/passwd to /usr/bin/git-shell or to whichever path it is otherwise located
  5. mkdir /opt/git
  6. chown -Rv git.git /opt/git
  7. chmod -Rv g+ws /opt/git
  8. cd /opt/git
  9. mkdir myproject.git
  10. cd myproject.git
  11. git init --bare --shared
  12. See addition to /opt/git/myproject.git/config below
  13. mv /opt/git/myproject.git/hooks/post-update.sample /opt/git/myproject.git/hooks/post-update
  14. On your local computer do:
    1. mkdir ~/tmp
    2. cd ~/tmp
    3. git config --global "Your Full Name"
    4. git config --global
    5. git init
    6. git add .
    7. git commit -m 'initial commit'
    8. git remote add origin
    9. git push origin master
      1. NOTE: if you get an error that origin already exists, do "git remote rm origin" before push
  15. Debug the set up, this guide probably has a few mistakes
Add this to /opt/git/myproject.git/config
    receivepack = true

Add apache functionality

  1. apt-get install apache2
  2. addgroup www-data git
  3. a2enmod auth_basic
  4. a2enmod authnz_ldap
  5. Add virtual host definition below
  6. service apache2 restart
The virtual host file is something like this, but you need to fix the "XXXX" part, best luck:
<VirtualHost *:80>
 DocumentRoot /opt/git
 ErrorLog ${APACHE_LOG_DIR}/git_error.log
 CustomLog ${APACHE_LOG_DIR}/git_access.log combined
 SetEnv GIT_PROJECT_ROOT /opt/git
 ScriptAlias / /usr/lib/git-core/git-http-backend/
 AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /opt/git/$1
 AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /opt/git/$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))$" \
 <LocationMatch ".*">
  AuthType Basic
  AuthName "XXXX"
  AuthLDAPURL ldap://bananas:389/XXXX
  AuthBasicProvider ldap
  AuthLDAPBindPassword XXXX
  require valid-user


Popular posts from this blog

Openvpn and unbound combined break dig command

Stress Linux system: stress-ng

Google Nexus 4: permanent back panel glass repair for less than a penny