Two versions of one line
You and a colleague edit one file today and fear losing each other's work, or showing a half-done page? This lesson shows how each works in a separate copy.
The scene
At nine on Thursday, Uncle Saber was in his photocopy kiosk across from the court, a roll of tape beside the copier. His customers ask him daily the way to the public counter, where people hand papers to the court. Ibrahim, the head clerk, came in to copy a page.
"I hear the counter moves to the ground floor on Sunday," Saber said. "I want the new 'How to reach us' page on my door. I close at two today, and not again until Sunday."
Ibrahim promised him the page before two.
At ten Ibrahim passed the office and saw the page open on two screens: Najla typing the new hours, and Faris, the new employee, drawing the map from the gate to the ground floor, both in one file. At eight he had heard Najla say, "I'm on the access page," and half an hour later, Faris saying the same. He thought of the old shared folder, its "final" and "final2", and the wrong file published from it. If one wiped out the other's work, the page would be late, and on Sunday people would wait at the old, closed counter.
He called Hussam from the IT office. Hussam opened the and showed a short list: he had made a branch for each of them, holding their work up to ten.
"These are . At the top is main, the : the copy we publish the court's page from. Under it, hours, where Najla works, and map, for Faris. Each began as a copy of main, and each Najla saves stays in her branch."
He clicked main: the old page, unchanged, with the counter on the first floor. "Their work hasn't reached here, and won't until we bring it into main. That's a ."
"So neither wipes out the other?"
"Not while each stays in their branch. The rest we'll see at the merge."
At one, Faris finished his map. At 1:05 Hussam merged his branch; it went through in seconds, and the map appeared in main. At 1:15 he merged Najla's, and the computer stopped. On screen was a : one line, in two versions.
From Faris's branch: "Counter on the ground floor, open until 2:00."
From Najla's: "Counter on the ground floor, open until 1:00."
The old line said "first floor, until 2:00". Faris had changed the floor to match his map and left the hour. Najla had changed both, as she heard at yesterday's meeting.
"Which is right?" Ibrahim asked.
"I don't know, and nor does the computer. It merged by itself everything only one of them changed; it won't pick an hour for this line."
"I'm not sure," Najla said. "The meeting was long."
Ibrahim phoned the court's administration, the office that sets working hours. At 1:30 came the answer: "The counter closes at one."
Hussam kept Najla's line, finished the merge and published the site. At 1:40 the new page was live. Ibrahim printed it and left.
At 1:55 Saber tore off four strips of tape, stuck the page to the kiosk door and smoothed it with his palm, then read the hours aloud. "I'll tell them: come before one, and copy your papers here first."
The idea
A branch gives each person a working copy; nothing reaches the published copy until merged.
- : a parallel copy where one person works and saves commits; nothing outside it changes.
- : the approved copy, usually named main. By agreement, work enters it only by merge, and it usually holds what people see.
- : bringing one branch's commits into another, automatic where each changed lines the other did not.
- : two branches changed the same line, so the computer stops, shows both, and a person decides.
If a colleague says "I'm on the file", ask which branch: in separate branches, neither can wipe out the other's work.
Try it yourself
- In your on GitHub, open the branch list and type a new name to create a : the list shows main and yours.
- Choose your branch, change a line, and save it as a with a saying why.
- Open main: the line is as it was before your change.
These steps show no conflict, which needs two branches changing one line. Leave your branch as it is: merging it on GitHub comes next.
Where this fits
Your work sits in its branch, and main is unchanged. Next, someone else reads and approves the work before the merge.