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

  • Can I mark submodule to use different then master branch by default
  • Remove version history of a single file in Git
  • Clone Failed while trying to checkout from bitbucket https url
  • git clone with https error - fatal: repository not found
  • Git pull not working properly?
  • Clone a repo with submodules: override credentials
  • How to clone git repository with specific revision/changeset?
  • Empty Git submodule folder when repo cloned
  • 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.