87

I created a Git repository using gitolite. Now I would like to rename that repository.

How can I do this?

In gitolite's readme is says that I should not work directly on the server. But I guess I have to do some work on the server in this case, right?

Patrick
  • 3,091
  • 4
  • 26
  • 29
  • Good question and thanks for the comment on my answer. Today i needed this answer ;) –  Apr 11 '11 at 04:35

4 Answers4

138

As stated in the gitolite basic-admin manual:

renaming a repo

This is similar; there's no code to do this in gitolite. What you do is:

  • log on to the server, cd $REPO_BASE (default: cd ~/repositories), and

    mv old-name.git new-name.git

  • back on your gitolite-admin clone, edit conf/gitolite.conf and replace all occurrences of old-name with new-name. Then add, commit, and push as usual.

The order of these 2 steps is important; do not reverse them :-)

A third step is necessary on gitolite3:

  • edit file gl-conf in the repo and change the repository name to the new name

And of course, every user should update his clone configuration to point to the new repo name.

campisano
  • 229
  • 2
  • 10
takeshin
  • 49,108
  • 32
  • 120
  • 164
  • 7
    On gitolite3 you also have to edit `gl-conf` and change the repository name. – Fernando Correia Nov 24 '13 at 19:00
  • 4
    don't forget to set the remote url of your local copy of the repo to the new name: `git remote set-url git@your.server:new-name.git`, then do a `git fetch` to make sure there are no errors. – cneuro Feb 23 '15 at 14:49
  • I'd done the first two steps in the wrong order before reaching this answer. FYI it also worked, just had to `rm -r new-name.git` before the `mv` command. – Arnaud P Aug 28 '17 at 14:03
9

I'm not familiar with gitolite specifically, but one approach that might work is to create a completely new repository with the correct name, push your code up into that one, and then delete the old one.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • From what i know that should keep the history. +1 –  Jan 17 '11 at 09:51
  • 1
    Deleting the old repository, creating a new repository and pushing the content of the old repository into the new one works. Thanks! – Patrick Jan 20 '11 at 17:12
  • Here are the commands to achieve this (assumes that NewRepo is already created in Gitolite): // In the old repo $ git remote add NewRepo $ git push --all --force NewRepo // In the new repo $ git pull No need to hack the gitolite config, and all the history retained :) – Matthew Skelton Jun 10 '13 at 08:26
0

Using Greg Hewgill as an idea, you possibly can rename the repository in the config file. You may want to try that on a dummy repository first. My suspicions is the old name will be deleted, the new will be created and you need to update your origins locally then push.

  • Unfortunately, renaming the repository in the config file doesn't work. gitlolite adds the new repository but does not delete the old one. Using Greg's idea works, though. – Patrick Jan 20 '11 at 17:11
  • @Patrick: Good to know, i havent needed to rename or delete one. –  Jan 21 '11 at 01:38
-1

A clean approach is to create the new repository as an empty one, then do the following:

Assuming old is OLD and new (empty) is NEW:

# mkdir /tmp/1
# cd /tmp/1
# git clone OLD_REPO old
# git clone NEW_REPO new
# cd new
# git pull ../old
# git push origin master

Or you can use directly the remote repo for OLD:

# mkdir /tmp/1
# cd /tmp/1
# git clone NEW_REPO new
# cd new
# git pull OLD_REPO
# git push origin master

This will keep all history and will let gitolite handle its internals. Additionally you'll have to update gitolite-admin but there's not limitation in the order.

This also works remotely without problems.

Deleting the OLD repository should be done per gitolite's instructions (locally) though.

V13
  • 853
  • 8
  • 14
  • I have write access to gitolite.conf, but I don't have write permissions on other git files hosted on gitolite server, so your solution worked perfectly for me. It is valid to mention that this method just copy the master branch to the new repo. – Lawrence Apr 06 '21 at 15:14