How I show the current branch even though there is no current branch #2918
amiryal
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
I think this is a time where |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
jj
has no notion (currently) of a “current branch”, but it can tell which branches are going to be pushed onjj git push
by default. According to the documentation, these are “any branches pointing toremote_branches(remote=<remote>)..@
”. Feeding this tojj log -r
will show us (among other things in the default log template) the branch we are working on, but it will return an empty result if our remote branch is already up to date:jj log -r 'remote_branches(remote="origin")..@ & branches()'
To see the branch we are working on regardless of when we
jj git push
, we may change the revspec to usetrunk()
orimmutable_heads()
instead ofremote_branches(…)
:jj log -r 'trunk()..@ & branches()'
Now, to see just the branch name, we can add a template:
jj log -r 'trunk()..@ & branches()' -T local_branches
This is already quite close to clean output, but we also don’t require the graph, and notice the keyword
branches
in there (plural). Multiple branches may refer to the same commit, or they may refer to multiple different commits in our chain of work, so we may get multiple branch names per line or multiple lines of output. Our final incantation takes care to output one branch name per line, without the graph:Personally, I use this as part of my shell prompt (hence the added
--ignore-working-copy
at the end). It could also potentially be incorporated somehow intojj status
, if it makes sense to the maintainers.Beta Was this translation helpful? Give feedback.
All reactions