3 Kai Wang (kaiwang@) and I (Jói Sigurðsson, joi@) experimented with something we called “shift-based development” in the first half of Q1 2013 as a way to work closely together on a componentization that was hard to do in parallel.
5 I work from Iceland, which is 7 or 8 hours ahead of Kai’s location (Mountain View, California), depending on the time of year (daylight savings time is not observed in Iceland). Kai and I were working on componentizing the Prefs subsystem of Chromium, and it was obvious early on that if we tried to develop in parallel, we would step on each others’ toes very regularly and be forced to do often difficult merges (due to e.g. moving files, renaming things, and so on). The idea came up, since my normal work day ends right around the time Kai’s starts, why not do the development in serial instead. Although I often work an extra hour or two later in the evening, that’s normally for responding to code review requests and email and not so much for coding, so this way we’d be completely free of getting in each others’ way.
7 The way we implemented this was we set up a bare git repository, and at the end of the day, we would push whatever we were working on to this repository, and let the other know the status of things. This could be a single working branch, or (more often) a pipeline of branches, plus a branch representing the SVN revision we were based off of. To make this work, we were both using the unmanaged git workflow.
9 The idea was, the next “shift” would pull down the pipeline of branches and continue where the last left off, doing development on the last change in the pipeline if it was incomplete, landing whatever changes could be landed, or starting a new change in the pipeline if all of them were ready for review or ready to land.
11 One limitation we ran into was that only the owner of an issue in Rietveld could upload a new patch set. To work around this limitation, I added a feature to Rietveld where you can add a COLLABORATOR=xyz@chromium.org line to your change description, which will allow that person to also upload patches and edit the change description (see [Rietveld patch](https://code.google.com/p/rietveld/source/detail?r=a37a6b2495b43e5fdd38292602d933714b7e8ddd)).
13 In my opinion this was moderately successful. We were probably less productive than we would have been if each of us had been working on completely unrelated things, but certainly more productive than if we had tried to work together on componentizing Prefs in parallel.
15 With more practice, I think this way of working together could be quite successful. It was also challenging and fun and could be a worthwhile thing to try for folks separated by close to a full working day or more. See details below if you'd like to try.
19 The following instructions assume Linux is being used, but should be easily adaptable to other OSes. If you find mistakes in the instructions, please feel free to correct and clarify this Wiki page.
23 On one of our Linux boxes, we set up a bare git repository using [these instructions](http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server). I'm sure you could also use an existing git service such as github.
25 Let's assume the IP address of the Linux box hosting the bare
26 repository is `12.34.56.78`, the Linux user that provides access to the
27 bare repository is named `gitshift`, and the repository is located at
28 `/home/gitshift/git/gitshift.git`.
30 Each developer participating in the shift-based development provides
31 their RSA public key (e.g. `~/.ssh/id_rsa.pub`) and we add it to
32 `/home/gitshift/.ssh/authorized_keys`; that way as long as you are using
33 `ssh-agent` and have run `ssh-add`, you won't need to type in a password
34 every time you issue a git command that affects the repository.
36 Issue these commands to add a remote for this repository to your local
37 git repo, and to mirror its initial state. You can call it whatever
38 you like, shiftrepo is just an example.
41 $ git remote add shiftrepo gitshift@12.34.56.78:/home/gitshift/git/gitshift.git
45 You should now be able to do a `git push` of some dummy branch; try
49 $ git checkout -b shifttest master
51 $ git add boo.txt && git commit -m .
55 The shared repository is just a place where you share your branches;
56 it is not a place where you do actual work. The actual work should be
57 done in your separate local repositories, and you still use e.g. git
58 pull (which in our git svn repositories behind the scenes does a `git svn fetch` etc.
60 Shift-based collaboration won't work well (at least not with a
61 pipeline of branches) unless you are using an "unmanaged" git checkout
62 (search for "unmanaged" on
63 [this page](https://code.google.com/p/chromium/wiki/UsingNewGit)).
65 ## Example Working Rules
67 For the branches we collaborated on, we set up some working
68 rules. This may be a good starting set and it worked well enough for us,
69 but others could adapt these rules:
71 a) We had a naming convention for pipelines of branches. E.g. you
72 might have branches named shiftrepo/p0-movemore and shiftrepo/p1-sync,
73 where p1-sync's upstream branch is p0-movemore, and p0-movemore's
74 upstream branch is an SVN revision, generally a version that was LKGR
75 at some point. You can find the git commit hash of this revision by
79 git log -1 --grep=src@ | head -1 | cut -d " " -f2
82 and the SVN revision number by running
85 git log -1 --grep=src@ | grep git-svn-id | cut -d@ -f2 | cut -d " " -f1
88 We followed a naming convention of one or two alphabetic characters
89 followed by the sequence number of the branch, followed by a dash and
90 a descriptive name for what's going on in that particular branch. The
91 one or two alphabetic characters indicated the rough over-arching
92 topic (e.g. p for Prefs), and the stuff after the dash can be more
95 b) When pushing a pipeline of branches to shiftrepo (where branch A
96 depends on branch B and so forth) we made sure to first git pull in
97 each dependent branch in sequence, so that each branch in shiftrepo is
98 building straight on top of the previous branch.
100 c) At the end of our shift, we did `git push shiftrepo branchname`
103 d) At the start of our shift, we did `git fetch shiftrepo` and then
104 for each branch we were collaborating on we did `git checkout branchname && git merge shiftrepo/branchname`. Note that the first command checks
105 out the local branch, and the second merges the shiftrepo/ branch into
106 it. This does not make the shiftrepo/ branch a parent of the local
109 e) Also at the start of each shift, we updated the local upstream
110 branches for each branch to match the upstream relationships that the
111 person ending their shift had on his end. One case is if the oldest
112 branch in the pipeline has been merged to a new LKGR, then we did this:
115 git branch --set-upstream oldestBranchName `git log -1 --grep=src@ oldestBranchName | head -1 | cut -d " " -f2`
118 and the other case is if new branches were created during the last shift, e.g. p4-foo was added, then for each we need to do like this:
121 git branch --set-upstream p4-foo p3-bar
124 f) For managing old branches, we removed the oldest branch in a
125 pipeline when several conditions were met:
127 > i) The old branch has been checked in.
129 > ii) The SVN revision of the check-in of the old branch is equal to
130 > or older than LKGR, i.e. that change in SVN is included when you
133 > iii) That LKGR has been merged into the old branch, and we've done
134 > `git pull` in the next branch after it.
136 g) We only used the CQ to commit stuff. The fear was (and this hasn't
137 really been validated as true or false) that there might be some
138 gotchas if we used `git cl dcommit` instead.
140 h) At the end of our shift, we communicated by email/IM/Hangout to let
141 the other know the status of the work, next steps remaining for any
142 currently-open branches, and to discuss what might make sense for the
143 next branches to work on.
147 To push a local branch to shiftrepo: `git push shiftrepo localbranchname`
149 To push all "matching" branches (i.e. push the latest copy of
150 any local branch that has previously been pushed to shiftrepo): `git push shiftrepo`
152 To delete a branch from shiftrepo, it's weird: `git push shiftrepo :branchname`