Skip to content

Chapter_4

Chris McIntosh edited this page Nov 21, 2019 · 2 revisions

Git on the Server

1 - The Protocols

  • bare repository refers to a repo without a working directory
    • The repo on the collaboration server for instance
  • Local Protocol
    • Refers to a locally available filesystem
    • Can be shared with an NFS mount for example
    • git clone <path/to/file> Directly copies the files
    • git clone file://<path/to/file> Uses the network protocol (which is less efficient locally)
      • the file:// method will strip extraneous files (such as after a migration)
    • git remote add <local proj> <path/to/file>
    • File based protocols are simple and use existing file permissions
    • Often more difficult to share if you are not on the same network
    • Often slower than an ssh based request
    • Every user has full shell access to the directory so it is risky in that aspect
  • HTTP Protocol
    • Smart HTTP
      • New since 1.6.6
      • Similar to SSH or git protocols
      • Runs over standard HTTPS ports and uses standard auth
      • Often the preferred protocol now since it is a single URL
    • Dumb HTTP
      • simple setup
      • Shove the git repo under HTTP root and setup a post-update hook (which comes with your default install)
    • Simple to use and doesn't require SSH keys (could be a con for advanced users)
    • Can serve read-only over HTTPS
    • Sometimes more tricky to setup than SSH
  • SSH Protocol
    • git clone ssh://<user>@<server>/<project>.git
    • Easy to use if you are already using SSH and have it setup to the server
    • Doesn't support anonymous access
    • People must have ssh access to the machine
      • Really? How does GitHub use SSH keys then? Surely I don't have ssh access
  • Git Protocol
    • Daemon listening on 9418
    • No Auth
    • Needs a git-daemon-export-ok file
    • extremely fast
    • Often paired with SSH or HTTPS for pushing

2 - Getting Git on a Server

  • git clone --bare <project> <project>.git Clones into a new bare repo (without the working directory)
  • Copy the new directory to your server
    • At this point the SSH protocol is ready, if SSH is set up on the server
  • git init --bare --shared sets up group write perms

3 - Generating Your SSH Public Key

  • Skipping, this just goes over ssh-keygen

4 - Setting up the Server

  • Skipping, this goes over saving public key's to the .authorized_keys folder as well as setting up SSH server

5 - Git Daemon

  • git daemon --reuseaddr --base-path=<path/to/repo> <path>/<to>/<repo>
    • --reuseaddr allows server to restart without waiting for old connections to timeout
    • --base-path allows cloning without the pull path
    • Uses port 9418 so you may need to punch a hole in your firewall
    • Can use systemd to daemonize the above command
    • In the valid repo's to get served you need to run touch git-daemon-export-ok to enable daemon access

6 - Smart HTTP

  • CGI script, so requires the use of some CGI server (Just apache?)
  • Need to set up .htpasswd in the git repo
    • Not the only way to have Apache authenticate though

7 - GitWeb

  • GitWeb is a basic CGI Script that visualizes your repo
  • git instaweb --httpd=webrick sets up a local webserver and sends your browser to it
  • For a more permanent solution you'll need to set up the CGI script to be hosted like the Smart HTTP protocol

8 - GitLab

  • Skipping... You can find an ami from Bitnami and run through the setup if you really want

9 - Third Party Hosting

10 - Summary

  • Useful Commands
    • git clone --bare <project> <project>.git
    • git init --bare --shared
Clone this wiki locally