Reset local repository branch to be just like remote repository HEAD

后端 未结 21 1582
挽巷
挽巷 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 02:56

    The question mixes two issues here:

    1. how to reset a local branch to the point where the remote is
    2. how to clear your staging area (and possibly the working directory), so that git status says nothing to commit, working directory clean.

    The one-stop-answer is:

    1. git fetch --prune (optional) Updates the local snapshot of the remote repo. Further commands are local only.
      git reset --hard @{upstream}Puts the local branch pointer to where the snapshot of the remote is, as well as set the index and the working directory to the files of that commit.
    2. git clean -d --force Removes untracked files and directories which hinder git to say “working directory clean”.

提交回复
热议问题