blob: 3d8f6454367745cc95018469c379558b2cfa1cd7 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:091# Introduction
2
3Kai 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.
4
5I work from Iceland, which is 7 or 8 hours ahead of Kais 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 Kais starts, why not do the development in serial instead. Although I often work an extra hour or two later in the evening, thats normally for responding to code review requests and email and not so much for coding, so this way wed be completely free of getting in each others way.
6
7The 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.
8
9The 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.
10
11One 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)).
12
13In 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.
14
15With 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.
16
17# Details
18
19The 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.
20
21## Setup
22
23On 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.
24
25Let's assume the IP address of the Linux box hosting the bare
26repository is `12.34.56.78`, the Linux user that provides access to the
27bare repository is named `gitshift`, and the repository is located at
28`/home/gitshift/git/gitshift.git`.
29
30Each developer participating in the shift-based development provides
31their 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
34every time you issue a git command that affects the repository.
35
36Issue these commands to add a remote for this repository to your local
37git repo, and to mirror its initial state. You can call it whatever
38you like, shiftrepo is just an example.
39
40```
41$ git remote add shiftrepo [email protected]:/home/gitshift/git/gitshift.git
42$ git fetch shiftrepo
43```
44
45You should now be able to do a `git push` of some dummy branch; try
46it out, e.g.
47
48```
49$ git checkout -b shifttest master
50$ echo boo > boo.txt
51$ git add boo.txt && git commit -m .
52$ git push shiftrepo
53```
54
55The shared repository is just a place where you share your branches;
56it is not a place where you do actual work. The actual work should be
57done in your separate local repositories, and you still use e.g. git
58pull (which in our git svn repositories behind the scenes does a `git svn fetch` etc.
59
60Shift-based collaboration won't work well (at least not with a
61pipeline 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)).
64
65## Example Working Rules
66
67For the branches we collaborated on, we set up some working
68rules. This may be a good starting set and it worked well enough for us,
69but others could adapt these rules:
70
71a) We had a naming convention for pipelines of branches. E.g. you
72might have branches named shiftrepo/p0-movemore and shiftrepo/p1-sync,
73where p1-sync's upstream branch is p0-movemore, and p0-movemore's
74upstream branch is an SVN revision, generally a version that was LKGR
75at some point. You can find the git commit hash of this revision by
76running
77
78```
79git log -1 --grep=src@ | head -1 | cut -d " " -f2
80```
81
82and the SVN revision number by running
83
84```
85git log -1 --grep=src@ | grep git-svn-id | cut -d@ -f2 | cut -d " " -f1
86```
87
88We followed a naming convention of one or two alphabetic characters
89followed by the sequence number of the branch, followed by a dash and
90a descriptive name for what's going on in that particular branch. The
91one or two alphabetic characters indicated the rough over-arching
92topic (e.g. p for Prefs), and the stuff after the dash can be more
93descriptive.
94
95b) When pushing a pipeline of branches to shiftrepo (where branch A
96depends on branch B and so forth) we made sure to first git pull in
97each dependent branch in sequence, so that each branch in shiftrepo is
98building straight on top of the previous branch.
99
100c) At the end of our shift, we did `git push shiftrepo branchname`
101for each branch.
102
103d) At the start of our shift, we did `git fetch shiftrepo` and then
104for each branch we were collaborating on we did `git checkout branchname && git merge shiftrepo/branchname`. Note that the first command checks
105out the local branch, and the second merges the shiftrepo/ branch into
106it. This does not make the shiftrepo/ branch a parent of the local
107branch.
108
109e) Also at the start of each shift, we updated the local upstream
110branches for each branch to match the upstream relationships that the
111person ending their shift had on his end. One case is if the oldest
112branch in the pipeline has been merged to a new LKGR, then we did this:
113
114```
115git branch --set-upstream oldestBranchName `git log -1 --grep=src@ oldestBranchName | head -1 | cut -d " " -f2`
116```
117
118and 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:
119
120```
121git branch --set-upstream p4-foo p3-bar
122```
123
124f) For managing old branches, we removed the oldest branch in a
125pipeline when several conditions were met:
126
127> i) The old branch has been checked in.
128
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
131> sync to LKGR.
132
133> iii) That LKGR has been merged into the old branch, and we've done
134> `git pull` in the next branch after it.
135
136g) We only used the CQ to commit stuff. The fear was (and this hasn't
137really been validated as true or false) that there might be some
138gotchas if we used `git cl dcommit` instead.
139
140h) At the end of our shift, we communicated by email/IM/Hangout to let
141the other know the status of the work, next steps remaining for any
142currently-open branches, and to discuss what might make sense for the
143next branches to work on.
144
145## Random Commands
146
147To push a local branch to shiftrepo: `git push shiftrepo localbranchname`
148
149To push all "matching" branches (i.e. push the latest copy of
150any local branch that has previously been pushed to shiftrepo): `git push shiftrepo`
151
152To delete a branch from shiftrepo, it's weird: `git push shiftrepo :branchname`