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
FR: Upsert branch (update branch or create if it does not exist) #3584
Comments
I believe we've pretty much achieved consensus on adding It should be fairly straightforward to add if you want to give it a try (check the existing implementations for |
Why have two separate subcommands ( |
@joyously only from an implementation perspective, I think.
|
I think it's okay to deprecate |
I agree with making The end result of both commands is the same: a branch exists and is set to a revision. I can't think of any use case where we would want to throw an error when setting a branch that doesn't exist. We could add a Once the we decide on the behavior, I can take up creating the PR. |
The typo problem is addressed for the case when you've typoed a branch name but accidentally produced another valid branch name (which happens), but it doesn't address the case when you create a new branch entirely unintentionally. (I recall cases earlier in my career where I spent some time trying to figure out, for example, why a push wasn't doing anything, where it turned out that I didn't actually update the branch that I thought I did, although this is somewhat mitigated by better tools for visualization.) (cc @ilyagr who I thought had complained about typos as well?)
The most obvious error case is when someone makes a typo in a branch name and they intended to update an existing branch. I'm opposed to making
(Another solution is to completely drop branches as a core feature, adopt topics or something else, and stop worrying about whether the branch UI makes sense 🤣) |
I'm all for this, but you still have the problem of defining what it is and how it works. If |
My opinion on the whole I'm also in favor of renaming the current branches concept to bookmarks, as they're totally misleading for long term Git users, and actually accurately describing the current behavior. |
I think there's a good amount of reflection from @arxanas's post, but I think there's also one element missing: just because how people work with computers changes doesn't mean everything should adapt. I think keeping creation and setting separate makes a lot of sense from a correctness standpoint. I'd much more strongly prefer we use Using |
To be clear, I don't mean [EDIT] I was wondering if we would add |
I've opened a PR to add the create option to set: #3585 I think the best point for this is that adding Another alternative could be prompting the user in the CLI to create the branch after |
I'm a little late to the discussion, but we could have (Indeed, as Waleed mentioned, I do regularly make typos and care about them) |
From my usage, it's often that I want to quickly create a branch after seeing it doesn't exist. For example:
Edit: Additionally, it matches the behaviour of other tools like |
That's a good point, |
(I thought |
I think the point was that adding |
Yeah, I agree, but if the user doesn't want to overwrite an existing branch, he doesn't have to try |
Is your feature request related to a problem? Please describe.
When working with Git, I need to remember if a branch is already created before updating it.
For example,
jj branch set my-branch -r @-
gives aError: No such branch
error. I then need to change the command tojj branch create my-branch -r @-
Describe the solution you'd like
An option on
jj branch set
such as-c
/--create
to create the branch if it does not exist.Example:
jj branch set my branch -r @- -c
Describe alternatives you've considered
Writing a shell alias for
jj branch set $args || jj branch create $args
(pseudo-code).The text was updated successfully, but these errors were encountered: