blob: 43b718ef932068c0355110732aca5db8e0cdf68f [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
sbc9f033f82015-11-26 00:50:5261pipeline of branches) unless you are using an "unmanaged" git checkout.
andybons3322f762015-08-24 21:37:0962
63## Example Working Rules
64
65For the branches we collaborated on, we set up some working
66rules. This may be a good starting set and it worked well enough for us,
67but others could adapt these rules:
68
69a) We had a naming convention for pipelines of branches. E.g. you
70might have branches named shiftrepo/p0-movemore and shiftrepo/p1-sync,
71where p1-sync's upstream branch is p0-movemore, and p0-movemore's
72upstream branch is an SVN revision, generally a version that was LKGR
73at some point. You can find the git commit hash of this revision by
74running
75
76```
77git log -1 --grep=src@ | head -1 | cut -d " " -f2
78```
79
80and the SVN revision number by running
81
82```
83git log -1 --grep=src@ | grep git-svn-id | cut -d@ -f2 | cut -d " " -f1
84```
85
86We followed a naming convention of one or two alphabetic characters
87followed by the sequence number of the branch, followed by a dash and
88a descriptive name for what's going on in that particular branch. The
89one or two alphabetic characters indicated the rough over-arching
90topic (e.g. p for Prefs), and the stuff after the dash can be more
91descriptive.
92
93b) When pushing a pipeline of branches to shiftrepo (where branch A
94depends on branch B and so forth) we made sure to first git pull in
95each dependent branch in sequence, so that each branch in shiftrepo is
96building straight on top of the previous branch.
97
98c) At the end of our shift, we did `git push shiftrepo branchname`
99for each branch.
100
101d) At the start of our shift, we did `git fetch shiftrepo` and then
102for each branch we were collaborating on we did `git checkout branchname && git merge shiftrepo/branchname`. Note that the first command checks
103out the local branch, and the second merges the shiftrepo/ branch into
104it. This does not make the shiftrepo/ branch a parent of the local
105branch.
106
107e) Also at the start of each shift, we updated the local upstream
108branches for each branch to match the upstream relationships that the
thakis993006d92016-06-15 13:51:23109person ending their shift had on their end. One case is if the oldest
andybons3322f762015-08-24 21:37:09110branch in the pipeline has been merged to a new LKGR, then we did this:
111
112```
113git branch --set-upstream oldestBranchName `git log -1 --grep=src@ oldestBranchName | head -1 | cut -d " " -f2`
114```
115
116and 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:
117
118```
119git branch --set-upstream p4-foo p3-bar
120```
121
122f) For managing old branches, we removed the oldest branch in a
123pipeline when several conditions were met:
124
125> i) The old branch has been checked in.
126
127> ii) The SVN revision of the check-in of the old branch is equal to
128> or older than LKGR, i.e. that change in SVN is included when you
129> sync to LKGR.
130
131> iii) That LKGR has been merged into the old branch, and we've done
132> `git pull` in the next branch after it.
133
134g) We only used the CQ to commit stuff. The fear was (and this hasn't
135really been validated as true or false) that there might be some
136gotchas if we used `git cl dcommit` instead.
137
138h) At the end of our shift, we communicated by email/IM/Hangout to let
139the other know the status of the work, next steps remaining for any
140currently-open branches, and to discuss what might make sense for the
141next branches to work on.
142
143## Random Commands
144
145To push a local branch to shiftrepo: `git push shiftrepo localbranchname`
146
147To push all "matching" branches (i.e. push the latest copy of
148any local branch that has previously been pushed to shiftrepo): `git push shiftrepo`
149
sbc9f033f82015-11-26 00:50:52150To delete a branch from shiftrepo, it's weird: `git push shiftrepo :branchname`