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 9261663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:11:17+00:00 2026-06-18T13:11:17+00:00

Suppose I pull changes from a git repo. Then the author of the repo

  • 0

Suppose I pull changes from a git repo. Then the author of the repo force pushes to the central repo. Now I can’t pull since the history is rewritten.

How can I pull the new commits (and abandon the old ones), assuming that the author force-pushed the correct version?

I know this is bad git workflow, but sometimes you can’t avoid this.

  • 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-06-18T13:11:18+00:00Added an answer on June 18, 2026 at 1:11 pm

    Throwing away your local changes

    If you want to discard your work, fetch and reset. For example, if you have a remote named origin and a branch named master:

    $ git fetch origin
    $ git reset --hard origin/master # Destroys your work
    

    Keeping your local changes

    If you don’t want to throw away your work, you will have to do a git rebase --onto. Suppose the old origin looks like this:

    A ---> B ---> C
                  ^
                  origin/master
    

    And you have this:

    A ---> B ---> C ---> X ---> Y ---> Z
                  ^                    ^
                  |                    master
                  origin/master
    

    Now, the upstream changes change things:

    A ---> B ---> C ---> X ---> Y ---> Z
     \                                 ^
      ---> B'---> C'                   master
                  ^          
                  origin/master
    

    You would have to run git rebase --onto origin/master <C> master, where <C> is the SHA-1 of the old origin/master branch before upstream changes. This gives you this:

    A ---> B ---> C ---> X ---> Y ---> Z
     \
      ---> B'---> C'---> X'---> Y'---> Z'
                  ^                    ^
                  |                    master
                  origin/master
    

    Notice how B, C, X, Y, and Z are now “unreachable”. They will eventually be removed from your repository by Git. In the meantime (90 days), Git will keep a copy in the reflog in case it turns out you made a mistake.

    Fixing mistakes

    If you git reset or git rebase wrong and accidentally lose some local changes, you can find the changes in the reflog.

    In the comments, a user is suggesting git reflog expire with --expire=now but DO NOT RUN THIS COMMAND because this will DESTROY your safety net. The whole purpose of having a reflog is so that Git will sometimes save your neck when you run the wrong command.

    Basically, what this command will do is immediately destroy the B, C, X, Y, and Z commits in the examples above so you can’t get them back. There’s no real benefit to running this command, except it might save a little bit of disk space, but Git will already purge the data after 90 days so this benefit is short-lived.

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

Sidebar

Related Questions

Suppose Song s have_many Comment s; How can I: Pull a list of all
Suppose I pull a field from the database, a timestamp field. How do I
Suppose I have a class Baz that inherits from classes Foo and Bar ,
I want to make additions to a Git, so that the original author is
I'm trying to pull in an src value from an XML document, and in
I have to pull data from at least 3 databases, is there anything wrong
I often face this problem with git: I clone a git repo of some
I have a query that is supposed to pull records from several tables using
I am new to git and github. Suppose I have a public github repository,
I have recently moved a project from SVN to git, and my colleague only

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.