No history yet

Branching for Experiments

Transcript

Beau

Okay, Jo. So, we've set up our repository on Bitbucket, we've connected it to SourceTree on our computer, and we've gotten into the habit of committing our changes. I have this… this one, single, beautiful timeline of my main lab protocol. It feels clean. It feels safe.

Jo

That's the whole point. The 'source of truth' we talked about. No more 'Protocol_Final_v3_USE_THIS_ONE.docx'.

Beau

Exactly! But now I have a problem. My PI wants me to try a new reagent for our PCR protocol. It might not work. I absolutely do not want to mess up my beautiful, clean, working protocol.

Jo

And you're worried that if you start editing the file, you might save over the original, or... get confused about which version is which, even with commits.

Beau

One hundred percent. My instinct is to do a 'Save As' and call it 'Protocol_New_Reagent_Test.docx', but we just agreed that's the dark path. So... what's the Git way?

Jo

The Git way is called 'branching.' And it's probably the most powerful feature for researchers. It's designed for exactly this scenario: experimenting in a safe, parallel universe without touching your stable, working version.

Beau

A parallel universe... I like that. So instead of a new file, I create a new... timeline? A new history?

Jo

Exactly. Think of your main protocol history—all those commits you made—as the trunk of a tree. When you want to try something new, you create a branch that grows off that trunk. You can make all the changes you want on that branch, and the main trunk remains completely untouched.

Beau

Okay, the tree analogy helps. So in SourceTree, how do I... grow a branch?

Jo

It's literally a button. At the top of your SourceTree window, there's a button that says 'Branch'. You click it, give your new branch a name—something descriptive, like 'pcr-new-reagent-test'—and hit create.

Beau

That's it? And once I do that... what happens? Does a new folder appear on my computer?

Jo

No, and this is the magic. Nothing looks different on your computer at first. Your protocol file is still there, named the same thing. But behind the scenes, Git now knows you're working on the 'pcr-new-reagent-test' branch. Any changes you commit from now on will be saved only on this new branch's timeline.

Beau

Whoa. So I can open my protocol file, change the reagent concentration, the incubation time, everything. Then I commit those changes with a message like 'Testing new reagent from XYZ company'. And my original, main protocol is... just safe?

Jo

Completely safe. It's like it doesn't even know your experiment is happening. Now, let's say your PI walks over and asks for the latest official version of the protocol. What do you do?

Beau

Panic? Uh, I guess I'd have to find the old version somehow? This is where it gets fuzzy.

Jo

No panic needed. In SourceTree, on the left side, you'll see a list under 'Branches'. You'll see your main branch—it's usually called 'main' or 'master'—and you'll see your new 'pcr-new-reagent-test' branch. To go back to the original, you just double-click on 'main'.

Beau

And what happens when I do that?

Jo

The file on your computer instantly reverts back to the version from the main branch. All your experimental changes vanish. You can print the protocol for your PI. Then, when they leave, you just double-click your 'pcr-new-reagent-test' branch again, and poof—all your experimental edits are right back where you left them.

Beau

Okay, hold on. That's... that's like time travel. Or dimension hopping. So 'checking out' a branch, which is what that double-clicking is called, right? It's basically telling my folder which timeline to show me.

Jo

That is a perfect way to put it. You're not changing files, you're changing which reality your folder is currently displaying. One reality is the stable, PI-approved protocol. The other is your experimental playground.

Beau

Okay, this makes so much sense for writing a manuscript too. You could have the main draft on the 'main' branch, but then create a 'shorten-for-nature' branch to try and cut it down, without losing your original text.

Jo

Exactly. And you can have multiple branches. One for the Nature draft, one for your PI's edits, one where you're reworking Figure 2. You can just hop between them. The history graph in SourceTree literally shows you this tree with all its branches. It's a visual map of your project's entire thought process.

Beau

So, final question. My PCR experiment with the new reagent... it worked! It's amazing, better results, cheaper, everything. Now I want this to be the *new* official protocol. My experiment needs to become the main trunk.

Jo

Great. That's called a 'merge'. You're telling Git: 'Take all the successful changes I made on this branch and merge them back into my main protocol.'

Beau

Is that also a button? Please say it's also a button.

Jo

It's... a right-click. First, you check out the branch you want to receive the changes—so, you double-click your 'main' branch. Then, you find your 'pcr-new-reagent-test' branch in the list, you right-click on it, and you select 'Merge... into current branch.'

Beau

And then the 'main' branch gets updated with my successful experimental changes. And what if the experiment had failed?

Jo

Then you just... abandon the branch. You can right-click and delete it. All those experimental commits just vanish, and your main protocol is exactly as it was, completely unharmed. No harm, no foul. You just tried something, it didn't work, and you pruned the branch off the tree.

Beau

That is a profoundly better way to work. It feels like a safety net for creativity, almost. You're free to try anything because you know you can't break the important stuff.