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

1

5

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?

Mcconaghy answered 5/6, 2021 at 4:27 Comment(1)
No, git doesn't know the name of the folder it's in. All of the information relative to the git setup is in the .git/ folderErlineerlinna
S
10

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.

Scauper answered 5/6, 2021 at 6:9 Comment(1)
I happened to rename the parent directory. After that each worktree directory refused to be recognized as git dir due to reason mentioned in this answer. I had to update the parent directory path in worktree/.git file of each worktree directory.Tourer

© 2022 - 2024 — McMap. All rights reserved.