Skip to content

Add episode on branching #1083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

davidwilby
Copy link

This draft PR is intended as a starting point for discussion on this topic as requested in #1022

I've added the episode on branches from https://github.com/carpentries-incubator/git-novice-branch-pr/ more or less verbatim albeit with name and format changes to match the new narrative. This is just added as 06b-branches.md for now to avoid complicating the diff by changing all the other file numbers but showing where it would fit into the order.

Points of discussion:

  • Timing: I'm reluctant to contribute to the bloat of lessons, though I think this is a very important topic to include in this lesson.
  • Should pull requests also be covered in this lesson? They are already covered with a good example in the incubator lesson linked above.
  • How/should the originators of the material used from the incubator lesson be credited here?
  • This branching episode uses examples of a python and a bash version of an analysis as its branches - would it be preferable to use something more aligned with the food/recipe themes instead?

Looking forward to a lively discussion on this and thanks for the opportunity to contribute!

Copy link

🆗 Pre-flight checks passed 😃

This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits.

It should be safe to Approve and Run the workflows that need maintainer approval.

@davidwilby davidwilby mentioned this pull request Apr 16, 2025
Comment on lines +49 to +52
In this lesson, Alfredo is trying to run an analysis
and doesn't know if it will be faster in bash or python.
To keep his main branch safe he will use separate branches
for both bash and python analysis.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to keep the "flavour" of Alfredo as a chef keeping his recipes under version control. So perhaps we could say he's experimenting with a new version of his famous strawberry cream cake in which he uses mango and less sugar, or something of the kind?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it goes this way, then the whole content should be adapted accordingly. A possibility would be something like he wants to experiment on his current cake recipe, and change the type of flour and also the type of sweetening. So he creates only one branch of a variant of the cake. Where he removes the old ingredients and adds the new ones. And then he wants to compare the cake to his previous version so he switches to main branch and prepares the other cake (the students will see the changes in the recipe file immediately having effect inplace). Then he decides that the new recipe is better, so he merges the changes of the new branch to main. It's basic but it's also in the "flavour" you mention, and it's possible to see an advantage of branching.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty much what I would suggest. But I think we need a good discussion on whether to do one branch or two branches, I'm not certain of my opinion.

Comment on lines +89 to +90
To switch to our new branch we can use the `checkout` command
we learned earlier and check our work with `git branch`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been changed, and we now try not to use checkout. The command we can use to move to another branch is git switch. We should teach that, even if it's newer, because checkout does many things and is confusing to beginners.

Comment on lines +102 to +105
Before we used the `checkout` command to checkout a file from a specific commit
using commit hashes or `HEAD` and the filename (`git checkout HEAD <file>`). The
`checkout` command can also be used to checkout an entire previous version of the
repository, updating all files in the repository to match the state of a desired commit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: checkout is no longer taught in this lesson, so this is not relevant any more. The comparison can be done with git restore if needed.

Comment on lines +119 to +124
For simplicity, we will `touch` the script making an empty file
but imagine we spent hours working on this python script for our analysis.

```bash
$ touch analysis.py
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make an experimental edit to an existing recipe instead.

git branch -D bashdev
```

```output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing the ending (usually each episode has a summary at the end)

@martinosorb
Copy link
Contributor

Thank you so much @davidwilby!
I'd love to see something similar.

I've left comments inline above. Summarizing and adding more general thoughts:

  • Flavour: I would keep something more in line with the current theme of recipes. An experimental version of an existing recipe could work,
  • git checkout: no longer taught. Let's use git switch instead, and compare with git restore.
  • The concluding summary is missing
  • Rather than having two new branches, each with a new file, and then merging one of them, I would suggest we only use one branch, do all the diffs, switch back and forth, and then decide to merge. Don't you think? I can also think of advantages of the current setup, to be honest, so let's discuss.
  • We should have a note to the instructors saying that this can be skipped if not relevant.

Copy link

@jorobledo jorobledo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added inline comments and answers to comments to attempt a more "in flavour" approach. Also, I propose to add a merge conflict example and solution, because it is something they will need to do quite early on their git experience with branches.

@@ -0,0 +1,329 @@
---
title: Branches
teaching: 20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite sure this can take 25 to 30 minutes. Also, I believe it important to give them an exercise to try it out themselves, because it's something that can be confusing and just trying it allows to fully understand what one is doing. maybe 5 to 10 for exercises?

So far we've always been working in a straight timeline.
However, there are times when we might want to keep
our main work safe from experimental changes we are working on.
To do this we can use branches to work on separate tasks in parallel

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can branch our timeline to work on separate tasks in parallel

I'm in".

```bash
$ git merge pythondev

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that one of the most complicated actions that a novice user of git needs to handle quite early is merge conflicts. In this case, everything works, but I thin it would make sense to make a merge conflict example where Alfredo needs to solve it, so that not only it is documented in the content on how to solve conflicts, but also the students understand the workflow of solving merge conflicts. What do you all think of adding this to the content?

Comment on lines +49 to +52
In this lesson, Alfredo is trying to run an analysis
and doesn't know if it will be faster in bash or python.
To keep his main branch safe he will use separate branches
for both bash and python analysis.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it goes this way, then the whole content should be adapted accordingly. A possibility would be something like he wants to experiment on his current cake recipe, and change the type of flour and also the type of sweetening. So he creates only one branch of a variant of the cake. Where he removes the old ingredients and adds the new ones. And then he wants to compare the cake to his previous version so he switches to main branch and prepares the other cake (the students will see the changes in the recipe file immediately having effect inplace). Then he decides that the new recipe is better, so he merges the changes of the new branch to main. It's basic but it's also in the "flavour" you mention, and it's possible to see an advantage of branching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants