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