Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:12:10+00:00 2026-05-30T00:12:10+00:00

I was accidentally working on a branch I shouldn’t have been for a while,

  • 0

I was accidentally working on a branch I shouldn’t have been for a while, so I branched off of it giving it the appropriate name. Now I want to overwrite the branch I shouldn’t have been on to the version from origin (github). Is there an easy way to do this? I tried deleting the branch and then resetting up the tracking branch, but it just gives me the version I was working on again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:12:11+00:00Added an answer on May 30, 2026 at 12:12 am

    If you haven’t pushed to origin yet, you can reset your branch to the upstream branch with:

    git checkout mybranch
    git reset --hard origin/mybranch
    

    (Make sure that you reference your latest commit in a separate branch, like you mention in your question)

    Note that just after the reset, mybranch@{1} refers to the old commit, before reset.

    But if you had already pushed, see “Create git branch, and revert original to upstream state” for other options.


    With Git 2.23 (August 2019), that would be one command: git switch.
    Namely: git switch -C mybranch origin/mybranch

    Example

    C:\Users\vonc\git\git>git switch -C master origin/master
    Reset branch 'master'
    Branch 'master' set up to track remote branch 'master' from 'origin'.
    Your branch is up to date with 'origin/master'.
    

    That restores the index and working tree, like a git reset --hard would.


    As commented by Brad Herman, a reset --hard would remove any new file or reset modified file to HEAD.

    Actually, to be sure you start from a “clean slate”, a git clean -f -d after the reset would ensure a working tree exactly identical to the branch you just reset to.


    This blog post suggests those aliases (for master branch only, but you can adapt/extend those):

    [alias]
       resetorigin = !git fetch origin && git reset --hard origin/master && git clean -f -d
       resetupstream = !git fetch upstream && git reset --hard upstream/master && git clean -f -d
    

    Then you can type:

    git resetupstream
    

    or

    git resetorigin
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on this iPhone app for a while now, and I had
Recently, while working on a shared host, I accidentally changed the permissions of my
Earlier it was working fine. I have been playing little bit config. So may
I accidentally added a file to my svn working copy that I don't want
while working on a project I accidentally noticed that the same method with only
While working on a Pylons app, I accidentally typed python setup.py install in the
I accidentally added a binary file to SVN with the add command, and now
Until now, I was always working on my own for PHP-projects, but at the
I accidentally deleted a major folder inside of the Tortoise-SVN Repro Browser. The working
I got my application working Awhile back, but after completely and accidentally deleting it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.