Skip to content
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

guide: branching strategies #196

Open
1 of 4 tasks
casperdcl opened this issue Feb 8, 2022 · 15 comments
Open
1 of 4 tasks

guide: branching strategies #196

casperdcl opened this issue Feb 8, 2022 · 15 comments
Labels
documentation Markdown files epic Collection of sub-issues p1-important High priority

Comments

@casperdcl
Copy link
Contributor

casperdcl commented Feb 8, 2022

Diagrams and guide for collaborative branching strategies (e.g. using cml pr for experiments in a large team, reporting, rebase vs squash-merging, hiding unneeded rows in Studio, etc.)

Also saving results https://stackoverflow.com/a/74563657/3896283

Also should mention caveats (e.g. cascading/nested PRs obscures reports).

Related resources:

Related issues (potentially duplicates and/or sub-issues):

@casperdcl casperdcl added documentation Markdown files epic Collection of sub-issues labels Feb 8, 2022
@0x2b3bfa0
Copy link
Member

0x2b3bfa0 commented Feb 8, 2022

More resources

flow

Click to reveal the source code of the diagram above...
const graphContainer = document.getElementById("graph-container");
const gitgraph = GitgraphJS.createGitgraph(graphContainer, {orientation: 'vertical-reverse', author: 'User <name@domain>'});

const main = gitgraph.branch("main");
main.commit("Initial commit");

const experiment = gitgraph.branch("experiment");
experiment.commit("Launch two experiments");

const first = experiment.branch("first");
first.commit({subject: "Add artifacts from the first experiment", author: 'Bot <runner@machine>'})
const second = experiment.branch("second");
second.commit({subject: "Add artifacts from the second experiment", author: 'Bot <runner@machine>'})

experiment.merge(first, "Merge artifacts from the first experiment");
main.merge(experiment, "Merge improvements from the experiment branch");

@jendefig
Copy link

I have a backlog item in my tasks "review this material for CML diagrams" pointing to this issue. Not sure why. Do you need this diagram recreated for docs or use case?

@casperdcl
Copy link
Contributor Author

I think this is more a @iterative/docs issue than a devrel one

@jorgeorpinel
Copy link
Contributor

I'd call this a p1 instead of an epic, at least from the description and within my understanding of what those labels mean.

@casperdcl casperdcl added p1-important High priority epic Collection of sub-issues and removed epic Collection of sub-issues labels Oct 3, 2022
@casperdcl
Copy link
Contributor Author

useful mentioned by @mjasion: https://mermaid-js.github.io/mermaid/#/gitgraph

```mermaid
gitGraph
   commit
   commit
   branch develop
   commit
   commit
   commit
   checkout main
   commit
   commit
   merge develop
   commit
   commit
```
gitGraph
   commit
   commit
   branch develop
   commit
   commit
   commit
   checkout main
   commit
   commit
   merge develop
   commit
   commit
Loading

@jendefig
Copy link

Question: what is happening in this part of the picture? why does checkout main pop up into that middle section between develop and main? When I checkout out to main, I'm not really on main, but in some kind of limbo? I'm not having an opinion on anything here. Just trying to legitimately understand. Been studying Pro Git. 😊 I was thinking when I checkout to main that I actually go back to main, but now I'm not sure.
image

@jorgeorpinel

This comment was marked as off-topic.

@jendefig

This comment was marked as off-topic.

@jorgeorpinel

This comment was marked as off-topic.

@casperdcl
Copy link
Contributor Author

casperdcl commented Nov 18, 2022

@jendefig actually raises a gewd point - someone new to Git graphs won't find the git command <> graph node mapping 100% intuitive.

image

@jendefig
Copy link

jendefig commented Nov 18, 2022

Thanks for this @casperdcl! This is how I was understanding how everything lined up. So is the blue line extending back to the develop branch because the merge occurred from the main branch. But if the merge occurred off the develop branch it would be yellow/chartreuse? Testing...

gitGraph
   commit
   commit
   branch develop
   commit
   commit
   commit
   checkout main
   commit
   commit
   checkout develop
   merge main
   commit
   commit
Loading

@jendefig
Copy link

Ok. I get it now. You are jumping when you checkout. The in-between lines are representing where the merge is coming from. Git is like being in a Christopher Nolan movie. 💡

@casperdcl
Copy link
Contributor Author

casperdcl commented Nov 23, 2022

indeed. Some non-obvious things:

  • line colours don't really have much meaning, especially colours of vertical lines between branches (corresponding to checkout/merge)
    • strictly speaking the line colours indicate which branch you were on before running commit/merge... but 'tis neither intuitive nor particularly useful info IMO
  • implicit arrow of time points from left to right (a concept literally used in quantum physics)
    • as commit number prefixes N- increase
  • merge commands are "special" commits that have at least 2 parents
    • since merges are commits, they should have a (N- prefixed) commit hash. This is missing (ARGH!)
  • a commit can exist in multiple branch histories. A "branch" is really just a label that can be moved to any commit. In fact each time you "add a commit to a branch" you really "add a commit on top of the existing one, then update the branch label to point to the new commit"

@jendefig
Copy link

Re: Color

I think it might be nice to have a generally agreed upon color for the main branch, but that's out of our control.

merge commands are "special" commits that have at least 2 parents

So the merge commit parents are the main and dev branches and the commit will appear in both, is that right?

  • since merges are commits, they should have a (N- prefixed) commit hash. This is missing (ARGH!)

ARGH x 2

a commit can exist in multiple branch histories. A "branch" is really just a label that can be moved to any commit. In fact each time you "add a commit to a branch" you really "add a commit on top of the existing one, then update the branch label to point to the new commit"

When you say "a label," just confirming you are using the term in a general sense, not at all referring to labels in GH, right? The label is the branch name, did I understand this correctly?

Thanks for these explanations! 🙏

@casperdcl
Copy link
Contributor Author

casperdcl commented Nov 29, 2022

merge commit parents are the main and dev branches

more accurate: merge commit parents are a particular pair of commits on the main and dev branches

and the [merge] commit will appear in both

no, the merge commit only appears in the target (main) branch, not the source (dev) branch

When you say "a label," just confirming you are using the term in a general sense

yes, in this case I mean "a label" in the general sense, as in "a human-readable name/alias for a commit hash". Git branches and Git tags are just aliases.

In fact a tag is identical a branch. We just (usually) assume tags are not meant to be moved/updated (use case: version numbers, tag v1.0.3 always refers to one commit) but branches are meant to be moved/updated (branch main is constantly updated to point to different commits).1

Footnotes

  1. there do exist some super-advanced scenarios that break this assumption 🐰🕳️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Markdown files epic Collection of sub-issues p1-important High priority
Projects
None yet
Development

No branches or pull requests

4 participants