Using personal git with cvs

If you are stuck using cvs in your dayjob, you may still get some mileage out of git. I will not discuss the cvs-git roundtrip tools, but rather how you can use git as a simple personal workflow enhancement.

First time setup

After installing git, remember to set your name and email in the global settings: 

git config --global user.name "Your Name"
git config --global user.email your@email.com
git config --global core.excludesfile ~/.gitignore

See ‘man git-config’ for other cool settings… 

Using git locally

I mainly use Git as a local “convenience” of sorts with CVS. I check out a module from CVS, and then do the following inside the toplevel directory: 

git init
git add .
git commit -m 'initial import'

NOTE: for this to work best, I have a global ~/.gitignore on ‘CVS’ and ‘.cvsignore’, to avoid versioning cvs metafiles in the local git repository… 

Then, I can work with the files locally, and commit small changes to git, revert my changes, etc. Whenever I feel like integrating new changes from other people, I do a 

cvs update

I can then use ‘git status‘ and ‘git diff‘ to look at what has happened, and resolve conflicts etc.

If I have made local changes not in CVS, I commit it to CVS. If I have made many small changes in git, this then ends up as a nice “atomic” bigger commit to CVS.

Once CVS is up-to-date with my changes, I usually then just commit everything change in CVS to git with 

git commit -a -m 'cvs sync'

If I do this several times without intervening local check-ins, I use the --amend option to git commit, to just add the new changes to the previous commit.

Using local branches and rebasing on CVS head

For the “advanced” user, it is very cool to do own development on a branch, and just leave the master to be in sync with CVS. 

git branch my_branch
git checkout my_branch
... work ...
git commit ...whatever...

I then switch back to master to sync with cvs, and then rebase the branch on head 

git checkout master
cvs update
git commit -a -m 'cvs sync'
git checkout my_branch
git rebase master
(possibly fix merge conflicts and...) git rebase --continue

Now, the branch is updated to be as if from the tip of HEAD, so future merges to CVS are easier.