Reset local repository branch to be just like remote repository HEAD

后端 未结 21 1590
挽巷
挽巷 2020-11-22 02:19

How do I reset my local branch to be just like the branch on the remote repository?

I did:

git reset --hard HEAD

But when I run a <

21条回答
  •  温柔的废话
    2020-11-22 03:08

    First, use git reset to reset to the previously fetched HEAD of the corresponding upstream branch:

    git reset --hard @{u}
    

    The advantage of specifying @{u} or its verbose form @{upstream} is that the name of the remote repo and branch don't have to be explicitly specified. On Windows or with PowerShell, specify "@{u}" (with double quotes).

    Next, as needed, use git clean to remove untracked files, optionally also with -x:

    git clean -df
    

    Finally, as needed, get the latest changes:

    git pull
    

提交回复
热议问题