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

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