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

RoyGoode's avatar

delete .git folder and init new one

I moved my laravel project folder and deleted the .git folder inside it to recreate it. I also made two new remotes (origin for bitbucket and production for server) for it but now I can no longer make changes to these remotes. (i have this repo on bitbucket and server) git push origin master

‍‍‍ Updates were rejected because the remote contains work that you do not have locally. ‍‍

Anyway, if I delete .git folder by mistake, how do I do this again?

0 likes
2 replies
jlrdw's avatar

You can start over and do a new push afterwards. In the future, don't delete .git, it can be moved with a project.

You just have to maybe re-establish the main, origin, etc.

Edit: I sometimes start over whnn .git gets too large, but don't on a public repository available to the public.

But for in-house and personal projects that git folder really grows.

2 likes
WadeShuler's avatar

Have you tried to get it off of one of the remotes?

For safety, make a backup of the project directory you currently have locally. A tar, zip, rar, whatever. Move it to a safe place. If you keep all your projects in a specific directory, rename the project's directory to prevent issues. "my-project-backup" or similar. The last thing you want to do is lose the actual files.

Following the instructions here: https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository

git clone <url>

You will have to re-create your remotes again.

Here is a guide for cloning a BitBucket repo: https://support.atlassian.com/bitbucket-cloud/docs/clone-a-repository/

Hope it helps.

*Additionally, you can force the push, but it probably isn't necessary. If one of your remotes has exactly what you want, you should be able to get it from there.

Please or to participate in this conversation.