I have a messed git repository. How to clean it?

This question already has an answer here:

  • Force my local master to be origin/master

    1 answer

  • Git script to rebase and squash temporary commits
  • Can not figure out how checkout works in git
  • Git very first steps
  • Filter git log to show only commits with notes
  • Php get Commit list of specfic Git Branch
  • How to isolate Eclipse workspace from git local repository?
  • Renaming RStudio project under version control
  • Push single outgoing commit in TFS Git
  • Git error 504 connecting to the server
  • Git: restore files stored in branch A, deleted in B
  • Git config: private remote url
  • fatal error: opening dependency file
  • One Solution collect form web for “I have a messed git repository. How to clean it?”

    You could simply reset your own branch to the one from origin

    git fetch origin
    git reset --hard origin/aBranch

    That would remove any local commit and local modification from the working tree, and reset everything to what is fetched from the upstream repo.

    If “origin” and “upstream” differ, you would need to “git push –force” one to the other (make sure the other collaborators are aware of that push).

    Git Baby is a git and github fan, let's start git clone.