How do I restore a project that has been created and deleted using git

Hi everyone,

I’m new to git I searched online but was confused. I was working with the team on a project, each person using a seperate branch. At point “A” I commited and pushed my changes, at point “b” I pushed some updates to github (or so I thought).

After a couple of days I tried to pull some updates from my colleagues branch, it created some conflicts and weird messages so I just deleted my branch from github and cloned his branch (I know not very smart). His branch does not have any of my previous pushed updates.

My first attempt was to get my previous work from github, but my branch was deleted, and then I opened github desktop to check the commit history, and I found out that my changes in point B were not pushed. But I’m pretty sure I did push (or at least commit those updates). I use visual studio 2019 to commit and push.

So now my question is… since my previous changes were committed, is there a way to get my project at point B at least locally from my computer?

This is a major project and I have no idea how to get my changes any help will be appreciated.

The key question is: Does the branch with your changes still exist in your local repository? If yes it should be easy, you can just check it out from the local repository and push to GitHub, or merge, or whatever else you need. I don’t know the Visual Studio integration so I can’t say which buttons to use, on the command line (e.g. Git Bash) git branch gives you a list of local branches, and git checkout BRANCHNAME switches to a specific one. You can also use git log BRANCHNAME to see the history of a specific branch (e.g. to check if it contains the things you’re looking for.

If the branch doesn’t exist any more it might still be possible to recover the commits if the garbage collector didn’t remove them as “unreferenced objects” yet. By default this happens after 2 weeks at the earliest. In that case you need to find the commit ID of the latest of your changes. Your best bet for that is probably to check git reflog. Once you have that, you can check it out and create a new branch from there.