Git Repository Collaboration

I know there are tons of tutorials out there about how to use git, but I thought I'd share my experiences so far anyway. I've decided to switch from using SVN to Git for managing my personal projects and utility scripts. I have two main reasons for this:
  • I'm using Git at work now and would like to increase my experience with it as much as possible.
  • I want to have (at least) two, decentralized repositories that I can merge at will. I want one on my laptop and the other on my desktop.
Creating a Git repository is super easy.
$ mkdir src
$ cd src
$ git init

To import your existing code, simply copy it to your new directory (or run git init in your existing code directory) and then:
$ git add .
$ git commit -a

All too easy. Now, the slightly trickier part is doing merging code between your various repositories. If you have sshd running on your hosts, you can do the merge over ssh. Here's what I did:
laptop$ git remote add desktop ssh://
laptop$ git branch -a

The git remote add command will add a new branch for each branch in the desktop repository. The branches will be named "desktop/master," etc. and can then be merged into the laptop repository like so:
laptop$ git merge desktop/master

Simple. Sweet.

No comments:

Post a Comment