Change Git repository directory location.
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Moving a Git repository to a different directory is usually simple: move the whole project folder, including its hidden .git directory, and Git keeps working. Problems only appear when people move part of the repository, forget external tooling that points to the old path, or are using advanced layouts such as separate Git directories or worktrees.
The Normal Case: Move the Entire Folder
In a standard repository, everything Git needs lives under the project directory. That means a plain filesystem move preserves the working tree, history, branches, remotes, and config.
If git status works after the move, the repository itself is fine. Git does not care that the parent path changed as long as the .git directory moved with the files.
This is true whether you use mv, Finder, Explorer, or a file manager. The key is moving the entire repository, not just the tracked files.
What Does Not Change
A directory move does not change:
- commit history
- branch names
- remote URLs
- tags
- local configuration stored in
.git/config
That surprises some developers who expect to “reinitialize” Git after the move. You do not need to run git init again. Reinitializing is unnecessary and risks confusion if done in the wrong directory.
Remote URLs also stay the same because they describe where the repository syncs, not where the local working copy lives.
What May Need Updating
Even though Git itself is usually unaffected, surrounding tools may still point to the old path. After a move, check:
- IDE workspace settings
- shell scripts with absolute paths
- CI jobs on the local machine
- editor bookmarks and launch configurations
- cron jobs or background services that run inside the repo
A repository move often fails operationally because of one of these external references, not because Git lost track of the project.
A Safer Move Workflow
When the repository is important or actively used, a short verification checklist helps:
If you have uncommitted changes, they move with the repository because they are just files in the working tree. You do not need to commit first, although doing so may reduce risk when the move is part of a larger reorganization.
Special Cases
Separate Git Directory
Some setups use a working tree in one place and the Git metadata elsewhere, for example with --separate-git-dir. In that case, the .git entry in the working tree is a pointer file, not a full directory. Moving the working tree may require updating that pointer.
Git Worktrees
If the repository uses git worktree, each worktree has metadata that records its location. Moving one of those directories manually can break the registration. The safer route is to remove and recreate the worktree using Git commands rather than dragging it around in the filesystem.
Submodules
Submodules can still work after a move if the whole parent repository moves intact, but scripts or tooling that assumed the old parent path may fail. Verify them explicitly.
If You Only Want a Different Name
Renaming the folder is just a move within the same parent directory:
From Git’s perspective, that is no different from moving to another path.
Common Pitfalls
The most common mistake is copying the project files without the hidden .git directory. That leaves you with source files but no repository metadata.
Another mistake is running git init in the new location after a successful move. That creates a new repository instead of preserving the old one.
A third issue appears with worktrees or separate Git directories. Those layouts store path relationships, so a manual move can break them even though a normal repository move would have been fine.
Summary
- In a standard repository, moving the whole folder preserves Git history and configuration.
- You do not need to reinitialize the repository after a move.
- Remotes do not change just because the local directory changes.
- Check IDEs, scripts, and local automation for old absolute paths.
- Be more careful with worktrees and separate Git directories, since those layouts track paths explicitly.

