Please note: this is written from the perspective of using the Git Bash shell.
- Clone the repository to be copied into a new location to ensure it is a fresh checkout
git clone old-repo-url checkout-location
cd into checkout-location, and run the following to checkout all branches from the remote:
for remote in `git branch -r | grep -v HEAD`; do git checkout --track $remote; done
- If it doesn’t already exist, create the new remote repository e.g.
- Add a new remote that points to the new repository:
git remote add new-repo new-repo-url
- Run the following to push all branches to the new remote:
git push --all new-repo
(If you haven’t yet seen it, Gitolite is a set of scripts for configuring a central Git server – see https://github.com/sitaramc/gitolite)
Renaming a repository is simple and fairly painless:
- Log onto your Git server (and any slaves), go to the repositories directory (by default it’s at
~/repositories), and rename your repository:
mv OldRepoName.git NewRepoName.git
- Update your Gitolite configuration to use the new repository name, and push your changes
However, if after renaming the repository you also want to continue supporting the old name (e.g. for a transition period while users move over to the new name), then you can use the alias feature of Gitolite to do that:
- Log onto your Git server, and open the “rc” file, which is at
- Look for the
INPUT variable, and add (or uncomment) the line
'Alias::input', inside the array (ensuring it is before the
'Mirroring::input' element), for example:
- Add a new variable called
REPO_ALIASES with the aliases you want to support:
'foo' => 'bar',
Now if you try to interact with the old repository (e.g.
git@server:foo) it will redirect to the new repo (
git@server:bar), giving the user a warning:
WARNING: 'foo' is an alias for 'bar'