Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to skip the staging area and (also) commit untracked, new files to git?

Is it possible to skip the staging area and (also) commit untracked, new files to git in a single built-in, command-line command ? If not, what are the alternatives ?

http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository

Providing the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the git add part:

$ git commit -a -m 'added new benchmarks'

Thanks.

like image 264
nutty about natty Avatar asked Apr 17 '13 19:04

nutty about natty


People also ask

Can we skip the staging area in git?

NOTE: Only tracked files can skip the staging area, to add your file to tracker type “git add --a” or “git add filename. extension”. Now let's skip the staging by typing “git commit -a -m “Commit Message””. Now if we do “git status” it will show that the working directory is clean.

Does git add stage untracked files?

Second, git add . adds both tracked and untracked files. Let's demonstrate this, by creating a file in the current directory as well as a file in a sub-directory. Now let's change into the sub-directory and run git add .

How do I fix nothing added to commit but untracked files?

To fix this error, either add the files causing the error to the staging area or ignore them using the . gitignore file.


2 Answers

Using a single, built-in, command-line command? No.

Using two commands:

git add -A
git commit

Using a custom alias:

Add this to .gitconfig:

[alias]
   commituntracked = "!git add -A; git commit"

Then you can do

git commituntracked
like image 87
Klas Mellbourn Avatar answered Sep 21 '22 04:09

Klas Mellbourn


This might seem quite trivial for the gurus, but is a minor revelation to me (I admit) - at least I just used it for the first time now and it works (without custom aliases): Just use a semicolon ; and it'll work as a one-liner:

git add --all; git commit -m "some informative commit message"

like image 27
nutty about natty Avatar answered Sep 20 '22 04:09

nutty about natty