Massey
Massey

Reputation: 1125

How to recover a locally only committed branch in git?

Somehow my local git got corrupted and I am getting, "fatal: Not a git repository (or any of the parent directories): .git". On one of the branches I have committed locally, but looks like that I have never pushed to the server. When I got a new repo on to a different folder, is there any way to recover that branch? In the new repo, when I try to checkout the branch, I am getting "the branch doesn't exist" message.

Thanks

Upvotes: 1

Views: 51

Answers (3)

Zeki
Zeki

Reputation: 5277

Worst case scenario, how about you clone from scratch, create a new branch and then copy the changed files from your corrupt local repository.

Upvotes: 0

gzh
gzh

Reputation: 3596

Added the older local repository as a remote of your new local repository, you can get those local branches in your old local repository.

Upvotes: 0

Raúl Martín
Raúl Martín

Reputation: 4679

As probably you know. All the info about your braches and commits are inside a folder call .git

I have a problem long time ago like that. If you still have it the folder you should try to clone the repository (diferent folder) again and copy the folders:

  • .git/refs (here you can see the list of your branchs)

  • .git/objects (you have the branch but you need the files info)

Hope you can recover your work!!!

Upvotes: 1

Related Questions