Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alihoushyaripour's avatar

How to recover .git directory?

Hi,

I pushed my code to git everyday, but yesterday .git folder of my project deleted and now I haven't it and can't get or download it again to push my new commit.

How can I recover or download it again?

0 likes
6 replies
automica's avatar

If you still have the file changes, and the remote repo, just check the project out again and copy your new files over the old and you should see file differences.

Can you clarify what your mean when you say ‘I cant download it again’ - as in you can’t ‘git pull’?

alihoushyaripour's avatar

@brightstormhq

When I push my code with:

git push -u origin master

show me this message to me:

fatal: unable to access 'https://gitlab.com/alihoushyaripour/test.git/': Failed to connect to user.email port 1080: Timed out
moharrum's avatar

Deleted .git folder can't be restored, unless you want to use a recovery tool. Anyway, since you've an online backup I think you should just clone it, if I where in ur place I would do the following:

  1. cd /home/MY_USER/projects
  2. git clone https://github.com/MY_USER/MY_PACKAGE.git
  3. cd MY_PACAKGE/

Then you can copy and paste changed files from ur existing local copy and then delete it.

jlrdw's avatar

I've had to git reset --hard

But look up any command before use, also backup stuff before messing with git commands.

backup stuff means at least temp copy to a good backed up place.

moharrum's avatar

BTW

What is your OS? files starting with a . dot are meant to be hidden under unix, linux, try ls -la see if the directory is there or not.

Additionally, with no .git dir, the message you get is fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

not a connection timed out response.

Also, if you are using some kind of a VPN like TOR gitlab will reject your ssh connection, you need to configure your remote upstream to use https instead.

Please or to participate in this conversation.