Many times I mistakenly add unwanted files to the staging area using the git add .
command.
I wonder if there is a way I could completely disable this command, so that I only use git add file
?
Many times I mistakenly add unwanted files to the staging area using the git add .
command.
I wonder if there is a way I could completely disable this command, so that I only use git add file
?
I guess it is a bad habit from svn, which has a default to add only tracked files [...]
You must unlearn what you have learned :)
You should run git status
often. If files you want to ignore get listed as untracked files, you should then edit your .gitignore
file, so that those files actually become ignored. Because git add
doesn't affect ignored (and untracked) files, you will then be able to use git add .
to stage all files of interest (and only those) in one fell swoop.
git add .
Git itself doesn't allow to do that, but if you really want to completely forbid the use of git add .
(and git stage .
, an exact equivalent), you can write a small wrapper around git
(in your ~/.<shell>rc
file) for that:
git() {
if [ "$1" = "add" -o "$1" = "stage" ]; then
if [ "$2" = "." ]; then
printf "'git %s .' is currently disabled by your Git wrapper.
" "$1";
else
command git "$@";
fi
else
command git "$@";
fi;
}