I’m using git with my friend.
I did a few commits and my friend didn’t update his local repo and pushed with -f arugment:
git push -f origin master
Now in the git server (github) my commits are destroyed and the latest commit is my friends. But I have a history of commits locally. Can I somehow merge them back to the master? Or I have to do it by hands with newest version?
Seems like your friend did change something already published on a public repository. See http://progit.org/book/ch3-6.html. Start by burning your friend.
Normally a git pull should trigger a merge on your side. You can always copy your whole repository as backup in case. Also you can simply copy the changes from your latest version to a new checkout and commit all of them as a single commit.