]> git.madduck.net Git - code/vcsh.git/blob - README.md

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix [mr] links
[code/vcsh.git] / README.md
1 vcsh - Version Control System for $HOME - multiple Git repositories in $HOME
2
3
4 # Index
5
6 1. [Introduction](#introduction)
7 2. [30 second howto](#30-second-howto)
8 3. [Overview](#overview)
9 4. [Getting Started](#getting-started)
10 5. [Usage](#usage)
11 6. [Contact](#contact)
12
13
14 # Introduction
15
16 [vcsh][vcsh] allows you to maintain several git repositories in one single
17 directory. They all maintain their working trees without clobbering each other
18 or interfering otherwise. By default, all git repositories maintained via
19 `vcsh` are stored in `$HOME` but you can override this setting if you want to.
20 All this means that you can have one repository per application or application
21 family, i.e. `zsh`, `vim`, `ssh`, etc. This, in turn, allows you to clone
22 custom sets of configurations onto different machines or even for different
23 users; picking and mixing which configurations you want to use where.
24 For example, you may not need to have your `mplayer` configuration on a server
25 or available to root and you may want to maintain different configuration for
26 `ssh` on your personal and your work machines.
27
28 `vcsh` was designed with [mr][mr], a tool to manage Multiple Repositories, in
29 mind and the two integrate very nicely. `mr` has native support for `vcsh`
30 repositories and to `vcsh`, `mr` is just another configuration to track.
31 This make setting up any new machine a breeze. It takes literally less than
32 five minutes to go from standard installation to fully set up system
33
34 A lot of modern UNIX-based systems offer pacakges for `vcsh`. In case yours
35 does not read `INSTALL.md` for install instructions or `PACKAGING.md` to create
36 a package, yourself. If you do end up packaging `vcsh` please let us know so we
37 can give you your own packaging branch in the upstream repository.
38
39 ## Talks
40
41 Some people found it useful to look at slides and videos explaining how `vcsh`
42 works instead of working through the docs, first.
43 They can all be found [on the author's talk page][talks].
44
45
46 # 30 second howto
47
48 While it may appear that there's an overwhelming amount of documentation and
49 while the explanation of the concepts behind `vcsh` needs to touch a few gory
50 details of `git` internals, getting started with `vcsh` is extremely simple.
51
52 Let's say you want to version control your `vim` configuration:
53
54     vcsh init vim
55     vcsh vim add ~/.vimrc ~/.vim
56     vcsh vim commit -m 'Initial commit of my Vim configuration'
57     # optionally push your files to a remote
58     vcsh vim <remote> add origin REMOTE
59     vcsh vim push origin master:master
60
61 If all that looks a _lot_ like standard `git`, that's no coincidence; it's
62 a design feature.
63
64
65 # Overview
66
67 ## From zero to vcsh
68
69 You put a lot of effort into your configuration and want to both protect and
70 distribute this configuration.
71
72 Most people who decide to put their dotfiles under version control start with a
73 single repository in `$HOME`, adding all their dotfiles (and possibly more)
74 to it. This works, of course, but can become a nuisance as soon as you try to
75 manage more than one host.
76
77 The next logical step is to create single-purpose repositories in, for example,
78 `~/.dotfiles` and to create symbolic links into `$HOME`. This gives you the
79 flexibility to check out only certain repositories on different hosts. The
80 downsides of this approach are the necessary manual steps of cloning and
81 symlinking the individual repositories.
82
83 `vcsh` takes this approach one step further. It enables single-purpose
84 repositories and stores them in a hidden directory. However, it does not create
85 symbolic links in `$HOME`; it puts the actual files right into `$HOME`.
86
87 As `vcsh` allows you to put an arbitrary number of distinct repositories into
88 your `$HOME`, you will end up with a lot of repositories very quickly.
89
90 To manage both `vcsh` and other repositories, we suggest using [mr](mr). `mr`
91 takes care of pulling in and pushing out new data for a variety of version
92 control systems.
93
94
95 The last logical step is to maintain all those new repositores with an automated
96 tool instead of tracking them by hand.
97 This is where `mr` comes in. While the use of `mr` is technically
98 optional, but it will be an integral part of the proposed system that follows.
99
100 ## Default Directory Layout
101
102 To illustrate, this is what a possible directory structure looks like.
103
104     $HOME
105         |-- $XDG_CONFIG_HOME (defaults to $HOME/.config)
106         |   |-- mr
107         |   |   |-- available.d
108         |   |   |   |-- zsh.vcsh
109         |   |   |   |-- gitconfigs.vcsh
110         |   |   |   |-- lftp.vcsh
111         |   |   |   |-- offlineimap.vcsh
112         |   |   |   |-- s3cmd.vcsh
113         |   |   |   |-- tmux.vcsh
114         |   |   |   |-- vim.vcsh
115         |   |   |   |-- vimperator.vcsh
116         |   |   |   `-- snippets.git
117         |   |   `-- config.d
118         |   |       |-- zsh.vcsh        -> ../available.d/zsh.vcsh
119         |   |       |-- gitconfigs.vcsh -> ../available.d/gitconfigs.vcsh
120         |   |       |-- tmux.vcsh       -> ../available.d/tmux.vcsh
121         |   |       `-- vim.vcsh        -> ../available.d/vim.vcsh
122         |   `-- vcsh
123         |       |-- config
124         |       `-- repo.d
125         |           |-- zsh.git  -----------+
126         |           |-- gitconfigs.git      |
127         |           |-- tmux.git            |
128         |           `-- vim.git             |
129         |-- [...]                           |
130         |-- .zshrc   <----------------------+
131         |-- .gitignore.d
132         |   `-- zsh
133         |-- .mrconfig
134         `-- .mrtrust
135
136 ### available.d
137
138 The files you see in $XDG\_CONFIG\_HOME/mr/available.d are mr configuration files
139 that contain the commands to manage (checkout, update etc.) a single
140 repository. vcsh repo configs end in .vcsh, git configs end in .git, etc. This
141 is optional and your preference. For example, this is what a zsh.vcsh
142 with read-only access to my zshrc repo looks likes. I.e. in this specific
143 example, push can not work as you will be using the author's repository. This
144 is for demonstration, only. Of course, you are more than welcome to clone from
145 this repository and fork your own.
146
147     [$XDG_CONFIG_HOME/vcsh/repo.d/zsh.git]
148     checkout = vcsh clone 'git://github.com/RichiH/zshrc.git' zsh
149     update   = vcsh run zsh git pull
150     push     = vcsh run zsh git push
151     status   = vcsh run zsh git status
152     gc       = vcsh run zsh git gc
153
154 ### config.d
155
156 $XDG\_CONFIG\_HOME/mr/available.d contains *all available* repositories. Only
157 files/links present in mr/config.d, however, will be used by mr. That means
158 that in this example, only the zsh, gitconfigs, tmux and vim repositories will
159 be checked out. A simple `mr update` run in $HOME will clone or update those
160 four repositories listed in config.d.
161
162 ### ~/.mrconfig
163
164 Finally, ~/.mrconfig will tie together all those single files which will allow
165 you to conveniently run `mr up` etc. to manage all repositories. It looks like
166 this:
167
168     [DEFAULT]
169     jobs = 5
170     # Use if your mr does not have vcsh support in mainline, yet
171     include = cat /usr/share/mr/vcsh
172     include = cat ${XDG_CONFIG_HOME:-$HOME/.config}/mr/config.d/*
173
174 ### repo.d
175
176 $XDG\_CONFIG\_HOME/vcsh/repo.d is the directory where all git repositories which
177 are under vcsh's control are located. Since their working trees are configured
178 to be in $HOME, the files contained in those repositories will be put in $HOME
179 directly.
180 Of course, [mr] [mr] will work with this layout if configured according to this
181 document (see above).
182
183 vcsh will check if any file it would want to create exists. If it exists, vcsh
184 will throw a warning and exit. Move away your old config and try again.
185 Optionally, merge your local and your global configs afterwards and push with
186 `vcsh run foo git push`.
187
188 ## Moving into a New Host
189
190 To illustrate further, the following steps could move your desired
191 configuration to a new host.
192
193 1. Clone the mr repository (containing available.d, config.d etc.); for
194    example: `vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr`
195 2. Choose your repositories by linking them in config.d (or go with the default
196    you may have already configured by adding symlinks to git).
197 3. Make sure the line 'include = cat /usr/share/mr/vcsh' in .mrconfig points
198    to an existing file
199 4. Run mr to clone the repositories: `cd; mr update`.
200 5. Done.
201
202 Hopefully the above could help explain how this approach saves time by
203
204 1. making it easy to manage, clone and update a large number of repositories
205    (thanks to mr) and
206 2. making it unnecessary to create symbolic links in $HOME (thanks to vcsh).
207
208 If you want to give vcsh a try, follow the instructions below.
209
210
211 # Getting Started
212
213 Below, you will find a few different methods for setting up vcsh:
214
215 1. The Template Way
216 2. The Steal-from-Template Way
217 3. The Manual Way
218
219 ### The Template Way
220
221 #### Prerequisites
222
223 Make sure none of the following files and directories exist for your test
224 (user). If they do, move them away for now:
225
226 * ~/.gitignore.d
227 * ~/.mrconfig
228 * $XDG\_CONFIG\_HOME/mr/available.d/mr.vcsh
229 * $XDG\_CONFIG\_HOME/mr/available.d/zsh.vcsh
230 * $XDG\_CONFIG\_HOME/mr/config.d/mr.vcsh
231 * $XDG\_CONFIG\_HOME/vcsh/repo.d/mr.git/
232
233 All of the files are part of the template repository, the directory is where
234 the template will be stored.
235
236     apt-get install mr
237
238 #### Install vcsh
239
240 #### Debian
241
242 If you are using Debian Squeeze, you will need to enable backports
243
244     apt-get install vcsh
245
246 #### Arch Linux
247
248 vcsh is availabe via [AUR](https://aur.archlinux.org/packages.php?ID=54164)
249 and further documentation about the use of AUR is available
250 [on Arch's wiki](https://wiki.archlinux.org/index.php/Arch_User_Repository).
251
252     cd /var/abs/local/
253     wget https://aur.archlinux.org/packages/vc/vcsh-git/vcsh-git.tar.gz
254     tar xfz vcsh-git.tar.gz
255     cd vcsh-git
256     makepkg -s
257     pacman -U vcsh*.pkg.tar.xz
258
259 #### From source
260
261 If your version of mr is older than version 1.07, make sure to put
262
263     include = cat /usr/share/mr/vcsh
264
265 into your .mrconfig .
266
267     # choose a location for your checkout
268     cd $HOME
269     mkdir -p ~/work/git
270     git clone git://github.com/RichiH/vcsh.git
271     cd vcsh
272     ln -s vcsh /usr/local/bin                       # or add it to your PATH
273     cd
274
275 #### Clone the Template
276
277     vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr
278
279 #### Enable Your Test Repository
280
281     mv ~/.zsh   ~/zsh.bak
282     mv ~/.zshrc ~/zshrc.bak
283     cd $XDG_CONFIG_HOME/mr/config.d/
284     ln -s ../available.d/zsh.vcsh .  # link, and thereby enable, the zsh repository
285     cd
286     mr up
287
288 #### Set Up Your Own Repositories
289
290 Now, it's time to edit the template config and fill it with your own remotes:
291
292     vim $XDG_CONFIG_HOME/mr/available.d/mr.vcsh
293     vim $XDG_CONFIG_HOME/mr/available.d/zsh.vcsh
294
295 And then create your own stuff:
296
297     vcsh init foo
298     vcsh run foo git add -f bar baz quux
299     vcsh run foo git remote add origin git://quuux
300     vcsh run foo git commit
301     vcsh run foo git push
302
303     cp $XDG_CONFIG_HOME/mr/available.d/mr.vcsh $XDG_CONFIG_HOME/mr/available.d/foo.vcsh
304     vim $XDG_CONFIG_HOME/mr/available.d/foo.vcsh # add your own repo
305
306 Done!
307
308 ### The Steal-from-Template Way
309
310 You're welcome to clone the example repository:
311
312     vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr
313     # make sure 'include = cat /usr/share/mr/vcsh' points to an exiting file
314     vim .mrconfig
315
316 Look around in the clone. It should be reasonably simple to understand. If not,
317 poke me, RichiH, on Freenode (query) or OFTC (#vcs-home).
318
319
320 ### The Manual Way
321
322 This is how my old setup procedure looked like. Adapt it to your own style or
323 copy mine verbatim, either is fine.
324
325     # Create workspace
326     mkdir -p ~/work/git
327     cd !$
328
329     # Clone vcsh and make it available
330     git clone git://github.com/RichiH/vcsh.git vcsh
331     sudo ln -s ~/work/git/vcsh/vcsh /usr/bin/local
332     hash -r
333
334 Grab my mr config. see below for details on how I set this up
335
336     vcsh clone ssh://<remote>/mr.git
337     cd $XDG_CONFIG_HOME/mr/config.d/
338     ln -s ../available.d/* .
339
340
341 mr is used to actually retrieve configs, etc
342
343     ~ % cat ~/.mrconfig
344     [DEFAULT]
345     # adapt /usr/share/mr/vcsh to your system if needed
346     include = cat /usr/share/mr/vcsh
347     include = cat $XDG_CONFIG_HOME/mr/config.d/*
348     ~ % echo $XDG_CONFIG_HOME
349     /home/richih/.config
350     ~ % ls $XDG_CONFIG_HOME/mr/available.d # random selection of my repos
351     git-annex gitk.vcsh git.vcsh ikiwiki mr.vcsh reportbug.vcsh snippets.git wget.vcsh zsh.vcsh
352     ~ %
353     # then simply ln -s whatever you want on your local machine from
354     # $XDG_CONFIG_HOME/mr/available.d to $XDG_CONFIG_HOME/mr/config.d
355     ~ % cd
356     ~ % mr -j 5 up
357
358
359 # Usage
360
361 ### Keeping repositories Up-to-Date
362
363 This is the beauty of it all. Once you are set up, just run:
364
365     mr up
366     mr push
367
368 Neat.
369
370 ### Making Changes
371
372 After you have made some changes, for which you would normally use `git add`
373 and `git commit`, use the vcsh wrapper (like above):
374
375     vcsh run foo git add -f bar baz quux
376     vcsh run foo git commit
377     vcsh run foo git push
378
379 By the way, you'll have to use -f/--force flag with git-add because all files
380 will be ignored by default. This is to show you only useful output when running
381 git-status. A fix for this problem is being worked on.
382
383 ### Using vcsh without mr
384
385 vcsh encourages you to use [mr][mr]. It helps you manage a large number of
386 repositories by running the necessary vcsh commands for you. You may choose not
387 to use mr, in which case you will have to run those commands manually or by
388 other means.
389
390 #### A Few Examples
391
392 To initialize a new repository: `vcsh init zsh`
393
394 To clone a repository: `vcsh clone ssh://<remote>/zsh.git`
395
396 To interact with a repository, use the regular Git commands, but prepend them
397 with `vcsh run $repository_name`. For example:
398
399     vcsh run zsh git status
400     vcsh run zsh git add -f .zshrc
401     vcsh run zsh git commit
402
403 Obviously, without mr keeping repositories up-to-date, it will have to be done
404 manually. Alternatively, you could try something like this:
405
406     for repo in `vcsh list`; do
407         vcsh run $repo git pull;
408     done
409
410
411 # Contact
412
413 There are several ways to get in touch with the author and a small but committed
414 community around the general idea of version controlling your (digital) life.
415
416 * IRC: #vcs-home on irc.oftc.net
417
418 * Mailing list: [http://lists.madduck.net/listinfo/vcs-home][vcs-home-list]
419
420 * Pull requests or issues on [https://github.com/RichiH/vcsh][vcsh]
421
422
423 [mr]: http://kitenet.net/~joey/code/mr/
424 [talks]: http://richardhartmann.de/talks/
425 [vcsh]: https://github.com/RichiH/vcsh
426 [vcs-home-list]: http://lists.madduck.net/listinfo/vcs-home