3

Say I need to rename a Git repository that has already been downloaded by a number of developers.

If I rename this repository, what side effects would happen, if any? I mean besides the developers having to perform a change in their local repository to change its remote repository like this

git remote set-url origin new_url

For the sake of the argument please consider that the Git server is a private one and all the developers form part of the same company.

For what it's worth, I have checked other questions regarding renaming repositories in Git, but none of them speak specifically about side effects except for the git remote change.

How does renaming a Bitbucket git repository affect forked repositories?

How do I rename a Git repository?

How do I rename a repository on GitHub?

Guillem Vicens
  • 3,776
  • 28
  • 43
  • 2
    Effect of changing the name: the name is changed. Side effect of changing the name: everyone who *uses* the name has to change it. Who uses the name? URLs, sure, but also local paths embedded in scripts, `--reference`s if there are any, and so forth. Find them all and change them, and you're done. Git generally can't help you find them as they're mostly outside Git. It could perhaps help a bit with `--reference` alternates; it doesn't, though; you have to look for those by hand, if you've used `--reference`. – torek Nov 04 '21 at 16:06
  • @torek, thanks for the comment. If that is all there is as side effect, then please post it as an answer and I will accept it. – Guillem Vicens Nov 08 '21 at 12:56

1 Answers1

2

As I said in a comment four days ago, the only real "side effect" of changing a name is that everyone use uses the name has to change their use as well. That's not exactly a side effect, since it's the main effect: you've changed the name!

The more interesting question is therefore: Who uses this name? Some of the answers here are obvious: it's stored in various URLs, typically under various "remotes" like origin:

$ git config --get remote.origin.url
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/

(this clone predates the public-access ones on GitHub, such as https://github.com/torvalds/linux, or I'd probably use that one). If Linus Torvalds were to rename his Git repository here, I'd have to change the stored URL. But you already called this out yourself.

So: where else might the name of the repository get stored? The only other places I can think of are:

  • in various shell scripts and YAML files and so on that, for whatever reason, them stored in them; and
  • in --shared and/or --reference clones, which set up what Git calls alternates within a repository.

If you have made such clones, you should check for this. It might be nice if Git had a more convenient way to do it, but basically the existing way to do it is to find all your .git directories and check for objects/info/alternates in them. See also What are the differences between git clone --shared and --reference?

Shell scripts, YAML files, and so forth have many forms and there's no universal way to find them all, though the obvious "grep" style check is obvious. (It could still miss any that got converted to binary with and/or compressed.)

torek
  • 389,216
  • 48
  • 524
  • 664