I started to version control a directory as follows.
git init
git add .
Then, I made modifications, adding/deleting/changing files. After I’m done with that, I run
git status
to get the following results.
# (use "git add/rm ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # deleted: bash/_bash_profile # deleted: bash/_bashrc # modified: functions.sh # modified: readme.txt # # Untracked files: # (use "git add ..." to include in what will be committed) # # bash/bash/ # template/
Now, I can do exactly what ‘git status’ told me to do.
For deleted file run git rm.
- git rm bash/bash_profile
For modified/added file run git add
- git add functions.sh
My question is this : how can I automatize this? I see that git already knows what action to do on the modified files.
- Is there a git command to do staging every necessary file according to its status? (remove or add)
- If not, is there any easy way to staging all the files instead of running ‘git add’ or ‘git rm’ one by one?
Yep, there’s an easy way:
This will add all modifications in the current directory (so run it from the top level of your repo if you want everything). It will not, however, add any untracked files. If you want to do that too, you use:
which will add all files in the current directory. (That means it’ll pick up modifications and untracked files, but not deletions like
add -u).Be sure and inspect
git statusbefore and after you do this, to make sure you’re getting exactly what you want staged. If you prefercommit -a, be even more careful to inspect the status. It’s very easy to add something you didn’t mean to commit.Have a look at the man page for more information.