简体   繁体   中英

Replace remote master branch with my local

I've been working on a project and things got sloppy. I've reset to a stable commit, but when I try to push I'm told "the current branch is behind its remote counterpart" (obviously). The only option that Git gives me to perform is git pull . When I try that I'm back to the newer, sloppy commits that don't work and I don't want.

I made a different branch called stable and ran reset --hard to the stable commit and then tried the following:

$ git checkout stable
  # =>  Switched to branch 'stable'

$ git merge -s ours master
  # =>  Already up-to-date.

$ git checkout master
  # =>  Switched to branch 'master'
  # =>  Your branch is behind 'origin/master' by 9 commits, and can be fast-forwarded (use "git pull" to update your local branch)

$ git merge stable
  # => Already up-to-date.

After running these commands my master branch is still in the state that I want to get rid of.

I'd like to have stable be the new master but am unsure what to do now.

You're looking for a force push (see the --force option). Just have a care with that as you probably do not normally want to change the history of a remote branch shared with other developers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM