Assuming I didnāt create another branch, and I want to go back to an older commit on the current branchā¦
git checkout oldcommitID
Now Iām in a ādetached HEADā state and git will show me helpful information here. Basically, now Iām not on any branch.
Now, if I make any changes, and then:
ā¦(not recommended) Try to push (to github) then it will prompt me on how to push to the HEAD of the remote branch.
ā¦(not recommended) Try to checkout the master (or some other) branch, then git will warn me that if I donāt want to lose my changes, then I should create a new branch to save them.
If I want to save my recent changes that I made while in the detatched HEAD state, then itās better to save them by creating a new branch:
git branch new-branch-name
and then I can merge them back in with master (see above).