Moving existing local GIT repository into a fresh gitolite setup
One of the tools I use is gitolite, a nice solution for hosting GIT repositories with privileges control and many more. Installation is trivial, just follow the tutorial instructions.
Let’s say you already have local repository and start to use gitolite on a remote server. This may happen when changing servers, git hosting provider etc. How to safely transfer your project? Firstly, you have to create new (usually bare) repository. In gitolite you just add to gitolite-admin/conf/gitolite.conf something similar:
repo test_repository RW+ = user
Then go to your local working copy and type:
$ git remote origin
This will show you all remote repositories that you used to connect with. In my case there was only “origin”, and it was the exact one I wanted to replace. With following commands you remove existing repository:
$ git remote rm origin
and add a new one:
$ git remote add origin firstname.lastname@example.org:test_repository.git
What will show more verbose version of “git remote” now?
$ git remote -v origin email@example.com:test_repository.git (fetch) origin firstname.lastname@example.org:test_repository.git (push)
That’s it. Now you can send your data to server:
$ git push origin master
Because it is very first “push” into an empty repo, you must explicitly point which remote and what branch you are sending data to. This will be remembered as default, so you don’t need to type it anymore. The same applies to the first “pull” or “fetch”:
$ git pull origin master