Force my local master to be origin/master

前端 未结 2 466
故里飘歌
故里飘歌 2020-12-13 02:17

I\'ve let master and origin/master get stuck in the sidelines, and am no longer interested in the changes on that branch.

I followed these instructions to get my loc

相关标签:
2条回答
  • 2020-12-13 02:55

    If git checkout -B master origin/master is not working for you (when you do git pull your local master are still stuck on an older origin/master branch), you can try this:

    git remote prune origin
    
    git pull
    

    It should reset your local master to track the latest origin/master.

    0 讨论(0)
  • 2020-12-13 03:04

    To have origin/master the same as master:

    git push -f origin master:master
    

    Discussion on the parameters:

    • -f is the force flag. Normally, some checks are being applied before it's allowed to push to a branch. The -f flag turns off all checks.

    • origin is the name of the remote where to push (you could have several remotes in one repo)

    • master:master means: push my local branch master to the remote branch master. The general form is localbranch:remotebranch. Knowing this is especially handy when you want to delete a branch on the remote: in that case, you push an empty local branch to the remote, thus deleting it: git push origin :remote_branch_to_be_deleted

    A more elaborate description of the parameters could be found with man git-push


    Opposite direction: If you want to throw away all your changes on master and want to have it exactly the same as origin/master:

    git checkout master
    git reset --hard origin/master
    
    0 讨论(0)
提交回复
热议问题