Just get it into git!

Trying my hand at git, I decided to take an existing cvs checkout and just load it into a new git repo.

So here’s my example: I have a checked out copy of a cvs module called “ldapadmin” that contains most of the scripts I’ve created for LDAP administration use over the last decade or so. This is located in my home directory under “~/cvs”. I’m going to create a new git repository under ~/projects called “ldapadmin” that I’ll use to keep track of all future changes.

First, configure git:

git config --global user.name "Phil Lembo"
git config --global user.email "me@mymail.com"
git config --global core.editor "gvim -f"
git config --global merge.tool "gvimdiff -f"

The syntax of those last two is important: graphical tools need to run in the foreground to prevent them from returning control to git before they complete their work and exit (see Git commit fails). To list the current config, run

git config -l

Then copy over the contents of the cvs module:

cd ~/projects
cp -R ~/cvs/ldapadmin .

What comes next is necessary because the files came out of my home directory. If yours were located somewhere else chances are they probably don’t need extensive changes to ownership/permissions.

Change permissions so that all can traverse and read the directory structure:

find ldapadmin -type d -exec chmod go+rx {} ;

Make sure your common group can read and write everything:

chmod -R g+rw ldapadmin

Now let everything be readable by all:

chmod -R o+r ldapadmin

Remove the vestigal “CVS” directories from all subdirectories (this is because the whole cvs module was copied over):

find ldapadmin -type d -name "CVS" -exec rm -Rf {} ;

Init as a git repo:

git init ldapadmin

Now cd into the repo add everything to git:

cd ldapadmin
git add .

(when not specifying individual files or parts of files by name it’s best to use a dot and not a bare ‘*’ wildcard, as the latter may cause a conflict)

Do an initial commit:

git commit

Check to make sure all it well:

git status

Results (more or less):

# On branch master
nothing to commit (working directory clean)

Change the “description” text to something “descriptive” (not really necessary but a nice finishing touch):

cd ~/projects/ldapadmin/.git
echo "ldapadmin project repo" > description

Now on to the doc to discover the right way to do it…