Search code examples
gitvisual-studio-2019git-reset

How do I reset a remote branch in Visual Studio 19


I had to reset the git branch I was working on to a previous commit. This only reset my local branch apparently. After making changes in my development environment I was unable to push them because the commit I had reset from locally still exists on the remote branch. I followed the steps to force push my local branch:

  1. In Team Explorer, Settings, checked the box to enable push --force.
  2. In Branches, I right-clicked on my (active) branch and selected Push.
  3. I got the warning "This branch is behind its remote counterpart..." and I clicked Yes to proceed.

screenshot of git warning

  1. It pushed the branch but then failed. The error in the Output window is:
Error: failed to push some refs to 'myrepourl'
Error encountered while pushing to the remote repository: PushCommand.ExecutePushCommand

I'm seeing others have had this issue and resolved it by pulling the remote changes. I would like to overwrite the remote changes however. Is this possible in Team Explorer? Or does this have to be done through the git cli?


Solution

  • If the remote has work that you don't have locally, did you try doing a "git fetch"? I'm not familiar with the GUI in VS but if you open a command prompt and navigate to the tracked folder, you can execute the two following statements:

    git fetch
    git pull
    

    git fetch will pull down the structure git pull will download any missing files you don't have locally.

    Edit...

    git commit -a -m "update message goes here"
    git push