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
folder inside the repository containing all relevant data and all other files build your working copyin a bare Git repository, there is no working copy and the folder (let's call it
repo.git
) contains the actual repository data
First,
backup
your existing repo:Second, run the following:
In short: replace the contents of
repo
with the contents ofrepo/.git
, then tell the repository that it is now a bare repository.To do this, execute the following commands:
Note that this is different from doing a
git clone --bare
to a new location (see below).The methods that say to remove files and muck about with moving the .git directory are not clean and not using the "git" method of doing something that's should be simple. This is the cleanest method I have found to convert a normal repo into a bare repo.
First clone /path/to/normal/repo into a bare repo called repo.git
Next remove the origin that points to /path/to/normal/repo
Finally you can remove your original repo. You could rename repo.git to repo at that point, but the standard convention to signify a git repository is something.git, so I'd personally leave it that way.
Once you've done all that, you can clone your new bare repo (which in effect creates a normal repo, and is also how you would convert it from bare to normal)
Of course if you have other upstreams, you'll want to make a note of them, and update your bare repo to include it. But again, it can all be done with the git command. Remember the man pages are your friend.
Simply read
Pro Git Book: 4.2 Git on the Server - Getting Git on a Server
which boild down to
Then put my_project.git to the server
Which mainly is, what answer #42 tried to point out. Shurely one could reinvent the wheel ;-)
I used the following script to read a text file that has a list of all my SVN repos and convert them to GIT, and later use git clone --bare to convert to a bare git repo
list.txt has the format
and users.txt has the format
www-data is the Apache web server user, permission is needed to push changes over HTTP
Oneliner for doing all of the above operations:
(don't blame me if something blows up and you didn't have backups :P)