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

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