8000 New context command for Local Branch : Fast-forward to HEAD · Issue #1318 · sourcegit-scm/sourcegit · GitHub
[go: up one dir, main page]

Skip to content

New context command for Local Branch : Fast-forward to HEAD #1318

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

Closed
goran-w opened this issue May 15, 2025 · 4 comments
Closed

New context command for Local Branch : Fast-forward to HEAD #1318

goran-w opened this issue May 15, 2025 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@goran-w
Copy link
Contributor
goran-w commented May 15, 2025

Sometimes (especially when doing modifications in a submodule, inside a super-repo) I end up (accidentally) committing something at a "detached HEAD".

(It's also easy to cause a detached HEAD by using the Checkout Commit context-command in the History graph, and then forget to checkout a branch before committing.)

Having done such a "detached" commit, there is a risk of losing the commit (and being forced to rescue it from reflog) if then checking out a branch.

Most likely, at least in the submodule case, HEAD was already coinciding with a branch-tip before my commit. What I'd like to do in this situation is simply to "move" that branch-pointer forward to point at my new commit. (A more cumbersome alternative would be to: create a temporary branch/tag to point at the new commit, checkout the original branch and reset it to the new commit, then delete the temporary branch/tag.)

However, there is no command in SourceGit to (forcefully) "move" a specified local branch-pointer so it points at another commit. There is the 'Reset <branch> to Here' command, but that only works for a checked-out branch. On the Git command-line, on the other hand, it's easy to accomplish what I describe (using the --force flag) :

git branch -f <branch> HEAD

Suggestion: add a context-command for Local Branches, similar to the 'Fast-forward to <remote tracking branch>' command, allowing us to "move" (or "fast-forward") any local branch so it points at the current (detached) HEAD.

The Git command for this would be git branch -f <branch> HEAD, but the context action could be implemented in one of two variants (depending on how much "sanity-checking" we want to apply) :

  • Fast-forward to HEAD
    • Needs additional check (git merge-base --is-ancestor <branch> HEAD; echo $?) to determine if <branch> can be fast-forwarded.
  • Move to HEAD
    • Needs no additional checks - is more general (and thus useful in more cases) but also a bit more "risky" (since we could lose track of the previous branch-tip, if the branch is "moved" to point at an earlier or unrelated/unreachable commit). This variant may need user confirmation before actually performing the action.

This command could be hidden or disabled (grayed-out) when HEAD is NOT detached. Alternatively, it could be always active, allowing us to re-point any local branch to the current commit (regardless of HEAD detached status).

NOTE: The 1st (safer) variant of this context-command could be incorporated into the 2nd (more general) variant, by implementing the ancestor-check as an option CheckBox 'Only allow fast-forward' (or similar) in a option/confirmation dialog for the command.

@gadfly3173
Copy link
Contributor

However, there is no command in SourceGit to (forcefully) "move" a specified local branch-pointer so it points at another commit. There is the 'Reset to Here' command, but that only works for a checked-out branch. On the Git command-line, on the other hand, it's easy to accomplish what I describe (using the --force flag) :

If you checkout to your branch, reset can be used.
Image

@goran-w
Copy link
Contributor Author
goran-w commented May 15, 2025

If you checkout to your branch, reset can be used.

Yes, I already mentioned that. But then I would lose my new commit, if HEAD is detached. 😉

@love-linger
Copy link
Collaborator

#1247

@love-linger
Copy link
Collaborator

Done.

Image

@love-linger love-linger 5B5A added the enhancement New feature or request label May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
0