Reputation: 145
I have a repository stored locally and on GitHub,
This repository is used to store the contents of my website,
After signing up to a CMS and it creating a hidden file in the GitHub directory I changed my mind and wanted to delete the hidden files.
I had performed
git pull origin master
In order to sync my local files with the files on GitHub, I then removed the hidden files locally and ran the following hoping it would sync the latest file with my local directory.
git add *
git commit -m "Removed CMS hidden files"
git push -u origin master
However, when doing this I get the following
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
deleted: .forestry/front_matter/templates/catalogue-entry.yml
deleted: .forestry/settings.yml
Untracked files:
.DS_Store
no changes added to commit
My desired outcome is to what I have locally synced exactly with my GitHub directory removing the hidden files added by the CMS.
Upvotes: 2
Views: 3983
Reputation: 9938
TL;DR; Use git add [--all|-A]
or git add [.|-A .]
or git add -u
or git add '*'
, instead of git add *
. One of them might work (use git status
to verify which works).
From this answer and this answer:
git add --all
orgit add -A
stages all changes on the whole working treegit add -u
stages modifications and deletions, without new files- In git version 1.x,
git add .
staged new files and modifications, without deletions - on the whole working tree.- From git 2.0,
git add .
(orgit add -A .
) however is to stage new/modified/deleted files (all changes) - but only on the current directory (./
directory)- To get the old behavior of
git add .
, we've to use--ignore-removal
About git add *
, from another answer:
In git,
add *
the*
is interpreted by the shell, and has nothing to do with Git. If your shell is Bash, files and directories starting with.
(hidden files on Linux) will not be matched by*
, so they will not be passed togit add
, and will not get added to the index.If
git add *
is being run in a Windows non-bash interpreter, the*
however will be passed literally togit add
. In this case files and directories whose names start with.
will get added.
So the behavior differs from Windows and Linux for git add *
, and the OP probably used a Linux/ git with a bash shell system, that's why he got the message:
Changes not staged for commit:
deleted: .forestry/front_matter/templates/catalogue-entry.yml
deleted: .forestry/settings.yml
after did git add *
, yet because (with bash shell) add *
didn't match the files start with .
.
Encourage you guys to read this answer to get more detail about git add *
.
Conclusion: Depends on cases (which directory you're on, whether you want to delete or add or modify, etc) one of my suggestions above might work, but git add [--all,-A]
happens to be the safest one to stage all changes include hidden files on the whole working tree - whole repository.
Upvotes: 6