Last Updated: August 15, 2019
·
3.229K
· rondale-sc

Git with intent to add!

When staging commits it is usually a good idea to use the --patch flag to review and split up your code accordingly. A common issue with this approach happens when you have added files. Since these files have only just been added they will be seen by Git as untracked files. When you run git-add with the --patch flag you will not see these untracked files (and more specifically the changes in them).

git config --global alias.gnap "'git add . -N && git add --patch'"

The -N flag means is short for --intent-to-add which will stage an empty file representing your newly added file. Then when git add --patch is called it will do the normal patch procedure over your newly created file's changes.

If no changes are patched in, the empty file will not be included in your commit. And there you have it.

Git with intent to add!!

1 Response
Add your response

Interesting use of the --intent-to-add option. I personally prefer the interactive mode, but this is worth knowing. Cheers

over 1 year ago ·