Skip to content
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

Reset local branch with the remote branch. #395

Closed
alexisfrjp opened this issue Oct 13, 2020 · 3 comments
Closed

Reset local branch with the remote branch. #395

alexisfrjp opened this issue Oct 13, 2020 · 3 comments
Assignees
Labels
feature request Feature request nice to have A feature request that is nice to have (lower priority)
Milestone

Comments

@alexisfrjp
Copy link

During a checkout from a remote branch, I'd like to be able to overwrite/reset the local branch with the remote branch. The remote branch has been force pushed and/or my local branch has changes not committed/stashed, then choosing Checkout the existing branch & pull changes will just lead to merge conflicts.

Error: Unable to Checkout Branch & Pull Changes
error: you need to resolve your current index first

Gitkraken has a feature Reset Local to Here when I want to checkout a branch.
I'd like to slowly replace GitKraken/GitAhead with a single tool such as Git Graph.

@alexisfrjp alexisfrjp added the feature request Feature request label Oct 13, 2020
@mhutchie
Copy link
Owner

Hi @alexisfrjp,

Thanks for this feature request, this would be great to have in Git Graph!

@mhutchie mhutchie added the nice to have A feature request that is nice to have (lower priority) label Oct 13, 2020
@mhutchie mhutchie added this to the v1.30.0 milestone Mar 1, 2021
mhutchie added a commit that referenced this issue Mar 3, 2021
…Dialog, allowing any local branch (that's not checked out) to be reset to the remote branch.
@mhutchie
Copy link
Owner

mhutchie commented Mar 3, 2021

I've explored numerous Git commands (and combinations of commands) that have the affect of resetting a local branch with a remote branch, while handling "remote branch has been force pushed and/or my local branch has changes". Each option has various subtle nuances and pro's & con's, however I believe I've implemented the option with the most net value for users (across many different workflows - not just the one specifically mentioned in this feature request).

From the remote branch context menu, the "Fetch into local branch..." action now has the option to "Force Fetch", which when enabled has the affect of "Force the local branch to be reset to this remote branch.". The only limitation is that the local branch can't be checked out when doing the Force Fetch, as most Git commands won't allow the checked out branch to be force updated.

In the use case you mentioned, I believe you would:

  1. Do a Force Fetch from the remote branch into the local branch
  2. Checkout the local branch

Please try out the implemented solution, and let me know if it works for your use case. If you don't think the implemented solution is workable, I'm more than happy to explore alternatives and implement them as well (as long as I haven't ruled it out for some reason).


This will be available in v1.30.0.

If you'd like to use it before the next release, you can download v1.30.0-beta.0, and install it following the instructions provided here.

@mhutchie mhutchie closed this as completed Mar 3, 2021
@Yuyan-Li
Copy link

Hello, I didn't want to open a new issue thus commenting here.

Resetting my current local branch on the remote is something I do very frequently. As this is not directly possible my work around is right-clicking the commit instead of the branch and then do the reset.

I've explored numerous Git commands (and combinations of commands) that have the affect of resetting a local branch with a remote branch, while handling "remote branch has been force pushed and/or my local branch has changes". Each option has various subtle nuances and pro's & con's

Could you explain this a little more? As I see it, a remote branch is no different to a local branch. This is even more clear as you can easily reset/rebase on the commit the remote branch is pointing to. So why shouldn't you be able to do it on the branch. (I'm referencing to rebasing on remote branches which I also often do. #329)

Resetting to the tracking remote branch in the command line would be done with.

git reset @{u}

But it could as well be done with the full branch name which also works for any remote branch

git reset origin/name-of-branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request nice to have A feature request that is nice to have (lower priority)
Projects
None yet
Development

No branches or pull requests

3 participants