Create a Bare repository from a local repository (non bare) - bahkified/Notes GitHub Wiki

A bare git repository contains the version control information only. It is only the .git folder with no working files. A non-bare git repository does contain working files as well as a .git folder. However, non-bare repositories cannot accept any push from external users. So in order to share code and collaborate with git, you must use a bare repository.

git init

A standard git command that will create a new local git repository. By default, it creates a non-bare repository, so it can contain working files and you can do work. If you now want to share this repository and collaborate with others, meaning other people will be pushing updates to the repository, this non-bare repo will not work.

There are two simple ways of doing this conversion.

1. The fastest way is to clone your old repository onto a new bare repository using the git clone command. Due to the way clone works, this will also setup your old non-bare repository as the new repository’s remotes. These can be removed with the git remote rm <name> command.

git clone —bare old_nonbare_repo new_bare_repo

2. The 2nd method is also straight forward, but has a few more steps. First create a new bare repository at the desired location. Then in your old repo, set the new repo as a remote and push your project onto the remote.

(create new directory and navigate to it)
git init --bare

(go back to your old repo)
git remote add dest <new_repo_url>
git push --all dest

You can now delete your old repo.

Resources

⚠️ **GitHub.com Fallback** ⚠️