I somehow set my head to a different address. I probably did a accidental checkout and reset head to point somewhere else. The issue now is that now the local repo's master branch is pointing to a random head from a few weeks ago.How can i set the local repo's head to match what the remote repo's master branch looks like. Ive been going back and forth with several commands and this is is what shows when I do the git reflog command. Thank you and I really appreciate it.
Asked
Active
Viewed 64 times
0

UI Developer
- 167
- 6
- 16
2 Answers
1
You can use git log
to show the list of commits, and then simply use the commit hash to reset the HEAD
git log
/* Shows list of commits */
git reset b10a4d7
Example git log
* 46a3ae9 (HEAD -> main) Fix JS syntax error
* faeed22 Do thing
* b10a4d7 (origin/main, origin/HEAD) Linting
* 7cb8974 Fix bugs
The hash to use is the one pointing to origin/main
or origin/master

Kieran101
- 565
- 5
- 18
1
If the current branch is master
(HEAD
points to master
) move the current branch to the same commit as remote-tracking branch origin/master
:
git reset --hard origin/master
If the current branch is not master
— first checkout then move:
git checkout master
git reset --hard origin/master
Another variant: first move non-current branch then checkout:
git branch --force master origin/master
git checkout master

phd
- 82,685
- 13
- 120
- 165