How can I convert a \'normal\' Git repository to a bare one?
The main difference seems to be:
in the normal Git repository, you have a .git
Here's what I think is safest and simplest. There is nothing here not stated above. I just want to see an answer that shows a safe step-by-step procedure. You start one folder up from the repository (repo) you want to make bare. I've adopted the convention implied above that bare repository folders have a .git extension.
(1) Backup, just in case.
(a) > mkdir backup
(b) > cd backup
(c) > git clone ../repo
(2) Make it bare, then move it
(a) > cd ../repo
(b) > git config --bool core.bare true
(c) > mv .git ../repo.git
(3) Confirm the bare repository works (optional, since we have a backup)
(a) > cd ..
(b) > mkdir test
(c) > cd test
(d) > git clone ../repo.git
(4) Clean up
(a) > rm -Rf repo
(b) (optional) > rm -Rf backup/repo
(c) (optional) > rm -Rf test/repo
In case you have a repository with few local checkedout branches /refs/heads/* and few remote branch branches remotes/origin/* AND if you want to convert this into a BARE repository with all branches in /refs/heads/*
you can do the following to save the history.
I think the following link would be helpful
GitFaq: How do I make existing non-bare repository bare?
$ mv repo/.git repo.git
$ git --git-dir=repo.git config core.bare true
$ rm -rf repo
Simply read
Pro Git Book: 4.2 Git on the Server - Getting Git on a Server
which boild down to
$ git clone --bare my_project my_project.git
Cloning into bare repository 'my_project.git'...
done.
Then put my_project.git to the server
Which mainly is, what answer #42 tried to point out. Shurely one could reinvent the wheel ;-)
Wow, it's simply amazing how many people chimed in on this, especially considering it doesn't seem that not a single on stopped to ask why this person is doing what he's doing.
The ONLY difference between a bare and non-bare git repository is that the non-bare version has a working copy. The main reason you would need a bare repo is if you wanted to make it available to a third party, you can't actually work on it directly so at some point you're going to have to clone it at which point you're right back to a regular working copy version.
That being said, to convert to a bare repo all you have to do is make sure you have no commits pending and then just :
rm -R * && mv .git/* . && rm -R .git
There ya go, bare repo.