Track but not stage a file with Magit
Published on
With the git
command line, one can use git add --intent-to-add
to track a file without staging the file, as documented on the git-add documentation. To quote from the documentation, this feature is useful for “showing the unstaged content of such files with git diff
”.
With magit, this feature is exposed via a prefix argument i.e. C-u s
on the magit-status
view. It’s documented in (describe-function 'magit-stage)
:
(magit-stage &optional INTENT)
Add the change at point to the staging area.
With a prefix argument, INTENT, and an untracked file (or files) at point, stage the file but not its content.
It took me a while to find this feature—prefix arguments have poor discoverability by default. They are often out of my radar when searching for functionalities, compared to the more discoverable standalone functions and keymaps that show up as completion candidates and which-key hints.