Using git for distributed development

As of today we are in early stages of development on a new UI approach for FreeIPA.  Since the “bits are very fresh” we want to keep from breaking the existing code base.  The policy for the upstream Repo for FreeIPA is that code must pass a fairly strenuous review process before getting checked in, and our code isn’t that way yet.  However, there are two of us  doing UI development, and we need to share our code back and forth prior to checking it in to the main repo.

This is a situation where git shines, and really can redefine your approach to development.  I realize I am a late comer to git.  I’m a bit of a Luddite, and slow to pick up on technologies in general, so this should come as no surprise.  Here’s our approach.

The developers are all “Fedora People.”  Which means, amongst other things, that we have accounts on the fedorapeople.org site.  The two accounts are pzuna and admiyo.  You can guess which one is me.

I started my git repo by cloning the FreeIPA repo.  I then added in remote entries for the pzuna and admiyo repos:

git  remote add admiyo git://fedorapeople.org/~admiyo/freeipa.git

git  remote add pzuna git://fedorapeople.org/~pzuna/freeipa.git

I can now refer to my repos by their short names.  To see the remote branches:

[ayoung@ayoung freeipa]$ git branch -r
admiyo/master
admiyo/webui
origin/HEAD -> origin/master
origin/ipa-1-0
origin/ipa-1-1
origin/ipa-1-2
origin/master
origin/webui
pzuna/master

I actually have a couple others on my remote repo that need to go away, but I’ve removed them from this list for clarity.

In order to build against a remote repo, I create a local branch that tracks the remote branch.  For my work, I created a branch called admiyo-master

git branch –track admiyo-master admiyo/master

To make sure that my changes are pushed to the remote repo, I run:

git push admiyo admiyo-master:master

To get in sync with changes that were made on the origin, I create a new branch:

git branch –track origin-merge origin/master

And then I checkout that new branch

git checkout origin-merge

And merge in my changes from admiyo-master”

git merge admiyo-master

In this case, it showed no conflicts.  I ran gitk at this point provides a visual confirmation that my merge worked.  Then it dawned on me:  I forgot to get the latest changes from origin.  So I ran:

git fetch

git rebase origin-merge origin/master

Which slides in the changes at the front of the merge.  After running “make rpms” to confirm that everything still builds, lets look at the state of the repo:

[ayoung@ayoung freeipa]$ git status
# Not currently on any branch.
# Untracked files:
#   (use “git add <file>…” to include in what will be committed)
#
#    RELEASE


nothing added to commit but untracked files present (use “git add” to track)

Again, som extra output is elided.

The final step is to synch this up to my fedorapeople repository:

git push admiyo origin-merge:master

This shows what the local repository looks like at the end.

The gitk application showing the state of the local repository after a merge

The gitk application showing the state of the local repository after a merge

Once I push to admiyo, I want to reset my admiyo-master branch:

git pull admiyo

Which will update all of the branches in my local repo that are based on admiyo/master.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.