This answers the question in the title.. not the question in the description, but I think some people who end up here might find this useful.
The following bash script adds and commits files in one command. IT DOES NOT ADD ALL FILES, it just adds files you specify on the command line. This could easily be modified to add all files if no files are specified on the command line. However, that seems a little dangerous to me so I haven't done it.
#!/bin/bash
if [[ $# -lt 2 ]]
then
echo "Usage: $(basename $0) FILENAME+ \"COMMIT_MESSAGE\""
echo
echo 'Shorthand for "git add FILENAME_0 FILENAME_1 .. FILENAME_n && git commit -m "COMMIT MESSAGE".'
echo 'You must specify at least one filename, and supply one single commit message.'
echo
else
git add ${*: 1: $#-1} && git commit -m "${*: -1}"
fi
Save it in a file called gac, say, and use it like this
gac file_a file_b file_c "adding three files because.. reasons"
Ripping on the work of @LuisEnMarroquin in this thread.
"yes the code in committed"
– Chassepotgit add .
is a quicker option for adding all – Velezgit add -A
and even worse,git add .
are both harmful and shouldn't be used in the vast majority of scenarios. You wantgit add -p
orgit add -i
to actually consider what you're staging. – Decal