Mirrors.mdwn 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Sometimes it's useful to have a repository on your server, which simply mirrors
  2. some other repository, on another server. Maybe it's easier for you to work with
  3. it like that, and create forks. Or the repository you want to use it hosted on
  4. a problematic server, e.g. a centralized hosting service, and you want to make
  5. the code available on an independent 100% free software powered system.
  6. # General Procedure
  7. In general, when creating a local personal mirror outside of Gitolite, the
  8. following procedure works.
  9. Create the repo:
  10. git init --bare
  11. Configure it:
  12. git remote add origin URL-HERE
  13. git config remote.origin.fetch +refs/*:refs/*
  14. git config fetch.prune true
  15. Run every hour/day/week to update the mirror:
  16. git fetch --quiet origin
  17. # G1thub
  18. However, Github has additional refs for pull requests, which can create a lot of
  19. unnecessary clutter and increase repo size.
  20. The following approach avoid them. However, it misses some namespaces git uses,
  21. such as notes and replacements. Most of the time they're not used anyway so I
  22. guess it's reasonable. Also, personally, most of the time I don't interact with
  23. Github. Anyway these namespaces can be added manually to the configuration if
  24. needed.
  25. The commands would be as follows.
  26. Create the repo:
  27. git init --bare
  28. Configure it:
  29. git remote add origin URL-HERE
  30. git config remote.origin.fetch +refs/heads/*:refs/heads/*
  31. git config --add remote.origin.fetch +refs/tags/*:refs/tags/*
  32. git config fetch.prune true
  33. Run every hour/day/week to update the mirror:
  34. git fetch --quiet origin
  35. # Gitolite
  36. Now let's see how it's done on a gitolite server.
  37. Create new empty repo (through gitolite-admin, as described in the previous
  38. sections of this guide).
  39. Become the git user (`# su - git`), go to the repository
  40. (`cd /home/git/repositories/my-mirror.git`) and apply the configuration commands
  41. on it as listed above (you can use the G1thub specific ones if you mirror a
  42. G1thub repo).
  43. Write a simple mirror.sh script to run the periodic update command:
  44. #!/bin/bash
  45. BASE=/home/git/repositories
  46. cd $BASE/my-mirror.git
  47. git fetch --quiet origin
  48. If you have several mirrors, you can extend the script to loop over them and run
  49. the git fetch command for each. Example:
  50. #!/bin/bash
  51. BASE=/home/git/repositories
  52. EXT=.git
  53. MIRRORS="
  54. bicon
  55. 4store
  56. raptor
  57. rasqal
  58. librdf
  59. redland-bindings
  60. redlandpp
  61. "
  62. for repo in $MIRRORS
  63. do
  64. cd ${BASE}/${repo}${EXT}
  65. git fetch --quiet origin
  66. done
  67. Another option is to go over all repositories, and use git-config to determine
  68. whether a repository is a mirror, e.g. by checking whether *gitweb.category*
  69. begins with "Mirror". But then you nee to make sure you assign gitweb categories
  70. consistently.
  71. Now become the git user and setup a cron job to run the script periodically
  72. (`crontab -e -u git`):
  73. # mail any output to `joe', no matter whose crontab this is
  74. MAILTO=joe
  75. # m h dom mon dow command
  76. # run at 4 AM every day
  77. 00 04 * * * /home/git/mirror.sh
  78. `crontab` opens your default text editor (e.g. nano or vim) and lets you add the
  79. new job. Simply append it to the end of the file.
  80. If you never used nano or vim - maybe it's time to learn, at least the basics.
  81. nano is quite simple: Ctrl-O saves, Ctrl-X quits. To learn the basics of vim,
  82. try `vimtutor`. For simple use it's enough to learn how to insert and delete
  83. text, how to save and how to quit. Summary:
  84. - hjkl or arror keys - navigate
  85. - `i` - (insert mode) type text at cursor position, delete with Backspace
  86. - Esc - stop insert mode (or any other mode, and go back to main mode)
  87. - `:w` Enter - save
  88. - `:q!` Enter - quit without saving
  89. - `:wq` Enter - quit and save
  90. Of course you can make Gedit or Kate etc. your default text editor, but then
  91. you'll be clueless when working on a GUI-less server or using SSH or when things
  92. crash. It's good to have a basic tool which is always available.
  93. If you want to read the e-mail sent to you (user *joe*) by cron, add a "local
  94. mbox" account to your e-mail client, and configure it to read from the file
  95. `/var/mail/joe`.