2

I often spend time 'experimenting' with code, rapidly prototyping different ideas before deciding on a final approach; but I'm struggling to find a good workflow that supports "checkpointing" my progress.

Using git I can easily commit at any stage, but jumping back and forward between commits on a branch rapidly becomes frustrating as I end up on headless branch and it's easy to lose further commits as they're not really tracked anywhere. Creating multiple branches like "featureA_simple_threshold_20", "featureA_simple_threshold_10", "featureA_complex_threshold_42" alleviates that problem, but leads to (what seems to me) a very messy workspace; and that's before conflicts start.

I've had a look at the recipy package for Python: https://github.com/recipy/recipy which is similar to what I'm looking for, but relies on persisting array-like objects, while I'll often just have a handful of print statements for my results.

This seems like it should be a pretty common use case, so are there any good workflows that can be recommended? Is there an alternative tool that could help me out here? (I'm primarily developing in Python, but this seems like a non-language specific problem)

B--rian
  • 5,578
  • 10
  • 38
  • 89
David258
  • 697
  • 2
  • 6
  • 15
  • 1
    Multiple branches are the way to go but once you've decided on an approach, delete (or merge/rebase if necessary) the other branches and get rid of them. Creating several prototypes is a good idea but throw away the bad ones. Also, if your history becomes messy because of a lot of tried this, then tried that, then back to the first option, etc. then simply do a rebase/squash operation to combine several back-and-forth commits into one. – Lasse V. Karlsen Nov 30 '17 at 16:57
  • I imagine that some combination of [tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) and [worktrees](https://git-scm.com/docs/git-worktree) would give you the flexibility you seek. But, speaking from experience, the chaos of your workflow is going to be pretty difficult to manage no matter what tool you use. You might want to consider dividing your work into smaller chunks that you can build on, rather than attempting a half-dozen monolithic branches. – JDB Nov 30 '17 at 19:08

1 Answers1

1

Creating multiple branches like ... alleviates that problem, but leads to (what seems to me) a very messy workspace;

Messy if you keep only one workspace.
But since Git 2.5, you can have multiple workspaces (one per branch) for one cloned repo. See "Multiple working directories with Git?".

Once you decide on a final approach, you can make that branch your main branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've not come across worktrees before, I might give those a whirl, they seem like they could help. – David258 Dec 01 '17 at 10:00
  • @David258 yes, sometimes trying to do *everything* in only one working tree can be messy. – VonC Dec 01 '17 at 12:24