How to replace a git repository?

31,375

You just need to use a little force:

git push --force origin master

--force can also be abbreviated to -f.

Share:
31,375

Related videos on Youtube

NARKOZ
Author by

NARKOZ

Updated on May 04, 2020

Comments

  • NARKOZ
    NARKOZ about 4 years

    I created a git repository and updated it with some stuff. Later I created a new directory for this project and initialized new git for it. Now I want to push changes and replace the old contents in the repository. When I run git push origin master I get

    ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]:Username/repo2.git'
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes before pushing again.  See the 'Note about
    fast-forwards' section of 'git push --help' for details.
    

    What can I do to solve this?

  • Defozo
    Defozo over 7 years
    What if one wants to keep previous commits and just add new things from new repo as another commit?
  • Suragch
    Suragch over 7 years
    @Defozo, see this answer.