How do you move or rename files so Git tracks it cleanly?
IntermediateConceptCommits, branches and tags
Answer
Use git mv old new, which is just mv plus staging both sides. Git infers the rename at diff time, so renaming a file and heavily editing it in one commit can break rename detection and hurt blame/history. Do the pure rename in its own commit.
git mv src/util.py src/helpers.py
git commit -m "refactor: rename util to helpers"
More on Commits, branches and tags
How do you write a good commit message?BeginnerWhat is the difference between `git add .`, `git add -A` and `git add -u`?BeginnerHow do you commit only part of the changes in a file?BeginnerHow do you change the last commit message or add a forgotten file?BeginnerWhat is the difference between `git switch`, `git restore` and `git checkout`?BeginnerWhat is the difference between lightweight and annotated tags?Beginner