]> 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:

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