How can I choose to overwrite remote repository with local commits?

后端 未结 4 1794
闹比i
闹比i 2020-12-25 10:42

Basically, due to events beyond my control, my remote repo was moved - I did a lot of work on my local copy in the meantime and now I really just want to overwrite everythin

相关标签:
4条回答
  • 2020-12-25 11:11

    I'm not an expert in github ecosystem, but why can't you just reset your remote repository url?

    git remote set-url origin /path/to/your/new/remote/repository/url
    

    You might also need to configure your up-stream branch by looking in here.

    for more on git remote..., please take a look here.

    0 讨论(0)
  • 2020-12-25 11:12

    How to do this for master branch, without pulling data down from the remote repo:

    1. Create a new folder, init git, add remote repo - don't pull or fetch!

      mkdir clean_repo

      git init

      git remote add origin <remote-repo>

    2. create (and switch to) empty local branch, add, commit and push a test file into this.

      git checkout test

      echo "test" > test

      git add .

      git commit -m "adding test"

      git push origin:test

    3. On github / bitbucket, change default branch to new branch

    4. On local, switch to master branch, commit and push to remote repo / branch

      git checkout -b master

      git push origin --mirror

    0 讨论(0)
  • 2020-12-25 11:13

    Been having the same problem. This command worked for me.

    git push --set-upstream origin master --force
    
    0 讨论(0)
  • 2020-12-25 11:26

    You can remove the branch and recreate it, let's say the branch that you want to overwrite is dev:

    Remove the branch in your remote host(github)

    git push origin :dev  
    

    Then just push your dev again:

    git push origin dev
    

    I use Github for hosting, not familiar with unfuddle, but I think it'll works for the unfuddle, too. :)


    Just as @melee mentioned, you can also use

    git push origin dev -f
    

    (not sure whether the -f is valid, but --force is OK)

    git push origin dev --force
    

    to force overwrite the branch. I remember I did it before. Thanks @melee. :)

    0 讨论(0)
提交回复
热议问题