Documentation / cvs-migration.txton commit Use GIT_REFLOG_ACTION environment variable instead. (f947413)
   1git for CVS users
   2=================
   3
   4Git differs from CVS in that every working tree contains a repository with
   5a full copy of the project history, and no repository is inherently more
   6important than any other.  However, you can emulate the CVS model by
   7designating a single shared repository which people can synchronize with;
   8this document explains how to do that.
   9
  10Some basic familiarity with git is required.  This
  11link:tutorial.html[tutorial introduction to git] should be sufficient.
  12
  13Developing against a shared repository
  14--------------------------------------
  15
  16Suppose a shared repository is set up in /pub/repo.git on the host
  17foo.com.  Then as an individual committer you can clone the shared
  18repository over ssh with:
  19
  20------------------------------------------------
  21$ git clone foo.com:/pub/repo.git/ my-project
  22$ cd my-project
  23------------------------------------------------
  24
  25and hack away.  The equivalent of `cvs update` is
  26
  27------------------------------------------------
  28$ git pull origin
  29------------------------------------------------
  30
  31which merges in any work that others might have done since the clone
  32operation.  If there are uncommitted changes in your working tree, commit
  33them first before running git pull.
  34
  35[NOTE]
  36================================
  37The first `git clone` places the following in the
  38`my-project/.git/remotes/origin` file, and that's why the previous step
  39and the next step both work.
  40------------
  41URL: foo.com:/pub/project.git/
  42Pull: refs/heads/master:refs/remotes/origin/master
  43------------
  44================================
  45
  46You can update the shared repository with your changes by first committing
  47your changes, and then using the gitlink:git-push[1] command:
  48
  49------------------------------------------------
  50$ git push origin master
  51------------------------------------------------
  52
  53to "push" those commits to the shared repository.  If someone else has
  54updated the repository more recently, `git push`, like `cvs commit`, will
  55complain, in which case you must pull any changes before attempting the
  56push again.
  57
  58In the `git push` command above we specify the name of the remote branch
  59to update (`master`).  If we leave that out, `git push` tries to update
  60any branches in the remote repository that have the same name as a branch
  61in the local repository.  So the last `push` can be done with either of:
  62
  63------------
  64$ git push origin
  65$ git push foo.com:/pub/project.git/
  66------------
  67
  68as long as the shared repository does not have any branches
  69other than `master`.
  70
  71Setting Up a Shared Repository
  72------------------------------
  73
  74We assume you have already created a git repository for your project,
  75possibly created from scratch or from a tarball (see the
  76link:tutorial.html[tutorial]), or imported from an already existing CVS
  77repository (see the next section).
  78
  79Assume your existing repo is at /home/alice/myproject.  Create a new "bare"
  80repository (a repository without a working tree) and fetch your project into
  81it:
  82
  83------------------------------------------------
  84$ mkdir /pub/my-repo.git
  85$ cd /pub/my-repo.git
  86$ git --bare init-db --shared
  87$ git --bare fetch /home/alice/myproject master:master
  88------------------------------------------------
  89
  90Next, give every team member read/write access to this repository.  One
  91easy way to do this is to give all the team members ssh access to the
  92machine where the repository is hosted.  If you don't want to give them a
  93full shell on the machine, there is a restricted shell which only allows
  94users to do git pushes and pulls; see gitlink:git-shell[1].
  95
  96Put all the committers in the same group, and make the repository
  97writable by that group:
  98
  99------------------------------------------------
 100$ chgrp -R $group /pub/my-repo.git
 101------------------------------------------------
 102
 103Make sure committers have a umask of at most 027, so that the directories
 104they create are writable and searchable by other group members.
 105
 106Importing a CVS archive
 107-----------------------
 108
 109First, install version 2.1 or higher of cvsps from
 110link:http://www.cobite.com/cvsps/[http://www.cobite.com/cvsps/] and make
 111sure it is in your path.  Then cd to a checked out CVS working directory
 112of the project you are interested in and run gitlink:git-cvsimport[1]:
 113
 114-------------------------------------------
 115$ git cvsimport -C <destination>
 116-------------------------------------------
 117
 118This puts a git archive of the named CVS module in the directory
 119<destination>, which will be created if necessary.
 120
 121The import checks out from CVS every revision of every file.  Reportedly
 122cvsimport can average some twenty revisions per second, so for a
 123medium-sized project this should not take more than a couple of minutes.
 124Larger projects or remote repositories may take longer.
 125
 126The main trunk is stored in the git branch named `origin`, and additional
 127CVS branches are stored in git branches with the same names.  The most
 128recent version of the main trunk is also left checked out on the `master`
 129branch, so you can start adding your own changes right away.
 130
 131The import is incremental, so if you call it again next month it will
 132fetch any CVS updates that have been made in the meantime.  For this to
 133work, you must not modify the imported branches; instead, create new
 134branches for your own changes, and merge in the imported branches as
 135necessary.
 136
 137Advanced Shared Repository Management
 138-------------------------------------
 139
 140Git allows you to specify scripts called "hooks" to be run at certain
 141points.  You can use these, for example, to send all commits to the shared
 142repository to a mailing list.  See link:hooks.html[Hooks used by git].
 143
 144You can enforce finer grained permissions using update hooks.  See
 145link:howto/update-hook-example.txt[Controlling access to branches using
 146update hooks].
 147
 148Providing CVS Access to a git Repository
 149----------------------------------------
 150
 151It is also possible to provide true CVS access to a git repository, so
 152that developers can still use CVS; see gitlink:git-cvsserver[1] for
 153details.
 154
 155Alternative Development Models
 156------------------------------
 157
 158CVS users are accustomed to giving a group of developers commit access to
 159a common repository.  As we've seen, this is also possible with git.
 160However, the distributed nature of git allows other development models,
 161and you may want to first consider whether one of them might be a better
 162fit for your project.
 163
 164For example, you can choose a single person to maintain the project's
 165primary public repository.  Other developers then clone this repository
 166and each work in their own clone.  When they have a series of changes that
 167they're happy with, they ask the maintainer to pull from the branch
 168containing the changes.  The maintainer reviews their changes and pulls
 169them into the primary repository, which other developers pull from as
 170necessary to stay coordinated.  The Linux kernel and other projects use
 171variants of this model.
 172
 173With a small group, developers may just pull changes from each other's
 174repositories without the need for a central maintainer.