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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:52:32+00:00 2026-06-11T19:52:32+00:00

Say I have an arbitrary local git working directory that was cloned from some

  • 0

Say I have an arbitrary local git working directory that was cloned from some remote. I want to make the local git repository be EXACTLY the same as the remote, irrespective of what’s happened to the local directory since it was cloned. I do not want to do another full clone.

Say the local working directory has:

  • additional untracked files
  • deleted files
  • staged changes.
  • may be on some arbitrary branch.
  • have a bunch of commits since being cloned from remote

Now I want to make this local repository reflect remote exactly. Here’s my current solution but I’m not sure if it covers all cases and whether there is an easier solution:

git stash
git clean -f -x -d
git checkout master
git fetch origin
git reset --hard origin/master
git pull origin master

Is there a better way to do 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-11T19:52:33+00:00Added an answer on June 11, 2026 at 7:52 pm
    git reset --hard
    

    will dump any changes that you have including any you have staged.

    git clean -xdf
    

    will get rid of anything in your working directory that git is not tracking due to ignore or exclude.

    git checkout HEAD
    

    will put you on no branch so you can clean everything out.

    git branch | xargs git branch -D
    

    will delete all your local branches

    git tag -l | xargs git tag -d
    

    will delete all your tags

    git prune origin
    

    will get rid of any tracking branches that are no longer on the remote

    git fetch
    

    will get any branches and tags from the remote that you don’t have. You can stop here and checkout any remote branches you want to work on while creating a local branch with

    git checkout origin/master
    

    or you can create local branches that point to where all existing remote branches are pointing to as of your fetch with

    git branch -r | xargs -n 1 git checkout
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class that allocates some arbitrary member data. There are
Say I have an array of arbitrary size holding single characters. I want to
Say I have a function that takes an arbitrary number of arguments (the last
Let's say that I have an arbitrary string like `A man + a plan
Lets say you have various objects of arbitrary type that you would like to
Say I have two (positive) arbitrary decimal numbers, a and b. I want to
Lets say I have an XML format similar to the following: <Random> <...Some arbitrary
Let's say you have a List<List<Boolean>> and you want to encode that into binary
Say I have a button embedded into my spreadsheet that launches some VBA function.
Let's say I have a list of arbitrary length, L: L = list(range(1000)) What

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.