6 gitcvs-migration - Git for CVS users
16 Git differs from CVS in that every working tree contains a repository with
17 a full copy of the project history, and no repository is inherently more
18 important than any other. However, you can emulate the CVS model by
19 designating a single shared repository which people can synchronize with;
20 this document explains how to do that.
22 Some basic familiarity with Git is required. Having gone through
23 linkgit:gittutorial[7] and
24 linkgit:gitglossary[7] should be sufficient.
26 Developing against a shared repository
27 --------------------------------------
29 Suppose a shared repository is set up in /pub/repo.git on the host
30 foo.com. Then as an individual committer you can clone the shared
31 repository over ssh with:
33 ------------------------------------------------
34 $ git clone foo.com:/pub/repo.git/ my-project
36 ------------------------------------------------
38 and hack away. The equivalent of 'cvs update' is
40 ------------------------------------------------
42 ------------------------------------------------
44 which merges in any work that others might have done since the clone
45 operation. If there are uncommitted changes in your working tree, commit
46 them first before running git pull.
49 ================================
50 The 'pull' command knows where to get updates from because of certain
51 configuration variables that were set by the first 'git clone'
52 command; see `git config -l` and the linkgit:git-config[1] man
54 ================================
56 You can update the shared repository with your changes by first committing
57 your changes, and then using the 'git push' command:
59 ------------------------------------------------
60 $ git push origin master
61 ------------------------------------------------
63 to "push" those commits to the shared repository. If someone else has
64 updated the repository more recently, 'git push', like 'cvs commit', will
65 complain, in which case you must pull any changes before attempting the
68 In the 'git push' command above we specify the name of the remote branch
69 to update (`master`). If we leave that out, 'git push' tries to update
70 any branches in the remote repository that have the same name as a branch
71 in the local repository. So the last 'push' can be done with either of:
75 $ git push foo.com:/pub/project.git/
78 as long as the shared repository does not have any branches
81 Setting Up a Shared Repository
82 ------------------------------
84 We assume you have already created a Git repository for your project,
85 possibly created from scratch or from a tarball (see
86 linkgit:gittutorial[7]), or imported from an already existing CVS
87 repository (see the next section).
89 Assume your existing repo is at /home/you/project. Create a new "bare"
90 repository (a repository withoupt a working tree) and fetch your project into
93 ------------------------------------------------
94 $ mkdir /var/www-data/deployment.git
95 $ cd /var/www-data/deployment.git
96 $ git --bare init --shared
97 $ git --bare fetch /home/you/project master:master
98 ------------------------------------------------
100 (See the "Using Git for collaboration" section in
101 linkgit:gittutorial[7] for an extended version of this example that
102 doesn't use a bare repository.)
104 Next, give every team member read/write access to this repository. One
105 easy way to do this is to give all the team members ssh access to the
106 machine where the repository is hosted. If you don't want to give them a
107 full shell on the machine, there is a restricted shell which only allows
108 users to do Git pushes and pulls; see linkgit:git-shell[1].
110 Put all the committers in the same group, and make the repository
111 writable by that group:
113 ------------------------------------------------
114 $ chgrp -R $group /var/www-data/deployment.git
115 ------------------------------------------------
117 Make sure committers have a umask of at most 027, so that the directories
118 they create are writable and searchable by other group members.
120 Importing a CVS archive
121 -----------------------
123 NOTE: These instructions use the `git-cvsimport` script which ships with
124 git, but other importers may provide better results. See the note in
125 linkgit:git-cvsimport[1] for other options.
127 First, install version 2.1 or higher of cvsps from
128 https://github.com/andreyvit/cvsps[https://github.com/andreyvit/cvsps] and make
129 sure it is in your path. Then cd to a checked out CVS working directory
130 of the project you are interested in and run linkgit:git-cvsimport[1]:
132 -------------------------------------------
133 $ git cvsimport -C <destination> <module>
134 -------------------------------------------
136 This puts a Git archive of the named CVS module in the directory
137 <destination>, which will be created if necessary.
139 The import checks out from CVS every revision of every file. Reportedly
140 cvsimport can average some twenty revisions per second, so for a
141 medium-sized project this should not take more than a couple of minutes.
142 Larger projects or remote repositories may take longer.
144 The main trunk is stored in the Git branch named `origin`, and additional
145 CVS branches are stored in Git branches with the same names. The most
146 recent version of the main trunk is also left checked out on the `master`
147 branch, so you can start adding your own changes right away.
149 The import is incremental, so if you call it again next month it will
150 fetch any CVS updates that have been made in the meantime. For this to
151 work, you must not modify the imported branches; instead, create new
152 branches for your own changes, and merge in the imported branches as
155 If you want a shared repository, you will need to make a bare clone
156 of the imported directory, as described above. Then treat the imported
157 directory as another development clone for purposes of merging
160 Advanced Shared Repository Management
161 -------------------------------------
163 Git allows you to specify scripts called "hooks" to be run at certain
164 points. You can use these, for example, to send all commits to the shared
165 repository to a mailing list. See linkgit:githooks[5].
167 You can enforce finer grained permissions using update hooks. See
168 link:howto/update-hook-example.html[Controlling access to branches using
171 Providing CVS Access to a Git Repository
172 ----------------------------------------
174 It is also possible to provide true CVS access to a Git repository, so
175 that developers can still use CVS; see linkgit:git-cvsserver[1] for
178 Alternative Development Models
179 ------------------------------
181 CVS users are accustomed to giving a group of developers commit access to
182 a common repository. As we've seen, this is also possible with Git.
183 However, the distributed nature of Git allows other development models,
184 and you may want to first consider whether one of them might be a better
185 fit for your project.
187 For example, you can choose a single person to maintain the project's
188 primary public repository. Other developers then clone this repository
189 and each work in their own clone. When they have a series of changes that
190 they're happy with, they ask the maintainer to pull from the branch
191 containing the changes. The maintainer reviews their changes and pulls
192 them into the primary repository, which other developers pull from as
193 necessary to stay coordinated. The Linux kernel and other projects use
194 variants of this model.
196 With a small group, developers may just pull changes from each other's
197 repositories without the need for a central maintainer.
201 linkgit:gittutorial[7],
202 linkgit:gittutorial-2[7],
203 linkgit:gitcore-tutorial[7],
204 linkgit:gitglossary[7],
205 linkgit:giteveryday[7],
206 link:user-manual.html[The Git User's Manual]
210 Part of the linkgit:git[1] suite