abhinav / git-spice

Manage stacked Git branches
https://abhinav.github.io/git-spice/
GNU General Public License v3.0
220 stars 11 forks source link

`branch create` without forcing an empty commit? #332

Closed matthiasr closed 2 months ago

matthiasr commented 2 months ago

I use branches as a "work context", and commits as an extended save, often cleaning them up later.

When I work on something new, I tend to

  1. create a branch for the thing I'm working on
  2. start hacking
  3. commit
  4. hack more
  5. commit more

Usually, by the time I commit for the first time, I have at least a rough idea of the shape of what I'm working on, but I don't when I create the branch. However, git-spice forces me to immediately make a commit, typing out at least some kind of message, to even create the branch.

I would prefer if gs branch create would only create the branch, still having it point at the same commit as the parent, like git checkout -b. In gs log long, I would expect this to look just like gs log short with no commit below the branch name.

I recognize that this is very much a matter of taste but wanted to register the preference 😄

abhinav commented 2 months ago

Hello! Yes, that's a valid workflow as well. I would be happy for git-spice to support it.

First, I want to mention what is already possible: You can currently do git checkout -b and gs branch track to get a branch without a commit.

git checkout -b foo && gs btr  # (shorthand for branch track)

Next, for a less boilerplate-y workflow: I'm supportive of adding a --no-commit flag [^1] to gs branch create which skips over all the committing logic, and just creates the branch, updates internal storage, and that's it. We could also add a configuration option (maybe spice.branchCreate.commit) that would allow you to set that flag by default. Then you'd be able to use gs branch create --commit for cases where you do want to commit.

[^1]: ...or rather a --commit flag that defaults to true, with a --no-commit negation for it.