Setup git-flow on Mac OS X Lion

git-flow is a branching model to keep your git repository in shape, and the author @nvie also released it as git extensions, so that you can easily convert your git repository into git-flow branch structure and keep maintained (with ease).

Below are the steps I setup git-flow on my Mac OS X Lion:

MacPorts and bash-completion

  1. Install Xcode
  2. Install MacPorts
  3. Install bash-completion

    % sudo port install bash-completion

  4. Add following line into .bash_profile, so that you can use default completions

    [ -f /opt/local/etc/bash_completion ] && . /opt/local/etc/bash_completion

git-bash-completion and git-flow-completion

After bash-completion is ready, you still need two additional completions before installing gitflow extensions.

  1. Install git-bash-completion

    % curl -O https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -o ~/.git-completion.sh

  2. Enable git-bash-completion by adding following into .bash_profile

    [ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh

  3. Install git-flow-completion

    % curl -O https://github.com/bobthecow/git-flow-completion/raw/master/git-flow-completion.bash -o ~/.git-flow-completion.sh

  4. Again, add following into .bash_profile to enable it

    [ -f ~/.git-flow-completion.sh ] && . ~/.git-flow-completion.sh

git-flow extensions

Once you completed steps above, the git and git-flow completions are integrated into bash, so we can proceed to the final step, install the git-flow git extensions:

% git clone --recursive git://github.com/nvie/gitflow.git
% sudo make prefix=/opt/local install

That’s it.

For usage, read this article.

Update

If you don’t mind installing dependent packages, you can use:

% sudo port install git-flow

Which saves lots of times, if it doesn’t break build.

References

Migrate from SVN to a remote Git Repository

Before today, I was using my lovely, 3 years old, Mac mini as remote Subversion server, and checkout projects to my MacBook through command-line tools or the limited Xcode’s SCM (software control management) Subversion support. And yes, I am not very satisfied with svn, and I bet you know the reason.

And Git is such a wonderful experience, if you tried GitHub. So, I was serious considering to migrate from Subversion to Git in these two days, but it’s really a hard decision, especially when Xcode is not supporting Git right now, which means you will have to make a turn and back to your shell prompt. But anyway, I stepped out into the bright sunlight from the darkness of…, huh, I switched. Cleanly moved from Subversion to a remote Git repository. Here are the steps, hope this helps those who wants to do the same:

Use MacPorts to install Git

Unlike other UNIX platforms, installing Git on Mac OS X is super easy. Assuming you had latest Xcode and MacPorts installed, then simply type the command in Terminal:

$ sudo port install git-core +svn +bash_completion

It takes maybe 10 to 20 minutes, depends on your CPU power, and everything is all set. I installed it on both my Mac mini (server) and Macbook (client).

Create Remote Repository on Server

Connect to the server, and setup a new “bare” Git repository:

$ ssh mini.local
Password:
Last login: Sat Mar 14 20:44:00 2009 from macbook.local
$ cd ~/
$ mkdir ~/git/
$ mkdir ~/git/projectname.git
$ cd ~/git/projectname.git
$ git --bare init
Initialized empty Git repository in /Users/digdog/git/projectname.git
$ exit

That’s it for the server side. You just create an empty remote repository for storing deltas and binaries later from your working Git repository.

Convert Subversion to Git from Client

Back to client side, first create a Git repository, and use git-svn to fetch code from your Subversion repository on the server, then clone it to a normal Git repository that does not have stuffs for supporting git-svn, and finally, push back to remote git repository.

Here’s how I did:

$ cd ~/
$ echo "digdog = digdog <digdog@my.email.address> > user.txt

Create a text file that contains username to allow us mapping from Subversion user to Git user later.

$ cd ~/
$ mkdir svn_to_git
$ cd svn_to_git
$ git svn init svn+ssh://mini.local/Users/digdog/svn/trunk/projectname --no-metadata
$ git config svn.authorsfile ~/user.txt
$ git svn fetch

Create a temporary directory called “svn_to_git”, then initialize this directory as Git repository, and point it to the SVN repository on my Mac mini server. Next, ask Git to use user.txt to map Subversion user to Git user in next command. Following the step sixth, fetch all the source code from server.

$ cd ~/
$ git clone svn_to_git temp_projectname
$ cd temp_projectname
$ git remote rm origin
$ git remote add origin ssh://mini.local/Users/digdog/git/projectname.git
$ git push origin master

In step two, clone the svn_to_git repository to a another temporary repository, which will will push back to remote repository later. And delete remote branch after cloning in step fourth. Step Five, add the remote repository to local temporary repository configuration, as a remote server called “origin”. At the end, we push local master branch (in temporary repository) to the origin’s master branch (on the server).

Clone from Remote Repository

So we finished, just clone it:

$ git clone ssh://mini.local/Users/digdog/git/projectname.git

and push/pull your code like a happy Git user.

References