I have some old local commits in the local master, so git status
shows that I' ahead of origin/master by 58 commits. I don't care about those old commits and would like to reset the local master to be current with the remote master. What's the preferred to do that? Ditto for another branch.
Asked
Active
Viewed 6,405 times
2

Michael
- 5,775
- 2
- 34
- 53
-
@SwissCodeMen, thanks, it answered the question, modified as in eftshift0's answer below. I should have found it myself. – Michael Jul 14 '21 at 20:42
2 Answers
5
if you don't care about anything in your current branch, then the simplest is to reset --hard
:
git checkout master
git reset --hard origin/master
This forces your local master to be like origin/master, in content and history. Use with care... anything in the working tree that is not committed will be set the way it is in origin/master.

eftshift0
- 26,375
- 3
- 36
- 60
1
In one command, since Git 2.23, using git switch -C
:
git switch -C master origin/master
This is a convenient shortcut for:
$ git branch -f <new-branch> $ git switch <new-branch>
As I explained in "Need to reset git branch to origin version", you would still need a git clean -f -d
to make sure any new and unstaged files are also removed (they would not be by a reset
/switch -C
alone).
Make sure to do a git clean -n -d
first though, to get a preview of what would be removed that was.

VonC
- 1,262,500
- 529
- 4,410
- 5,250