Search code examples
gitrenamegit-repo

What happens when I rename the parent directory of a git repo?


If I have a git repo in a folder named some-folder, and I change it to another-folder, is there going to be any problems?


Solution

  • The answer here is both no and yes.

    In many (most?) cases, Git will have no issues at all, as Git works relative to the top level of the working tree and the .git directory.

    When using git worktree, however, and/or when the repository may be referred-to by other users as a remote—for instance, when you're on a server that serves Git requests—it's possible that there are absolute path references to that particular repository. If so, any references outside the repository itself will need to be updated. For instance, if you're working with the Git repository on your company's main Git server, and it resides in /exports/repos/path/to/repo.git and you change this to /exports/repos/repository.git, it's likely that everyone in the company must change their URLs from ssh://example.com/path/to/repo.git to ssh://example.com/repository.git.

    So, the answer is to pay attention to the surrounding context in which the repository is used. Git itself is not likely to have issues here, but other people might. If you are using extra work-trees, consider how they may be affected, too.