Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit and automatically add all untracked files

Tags:

git

I often forgot that I have some new files and directly do,

git commit -a -m "My commit message" 

This only commits changed files, and I have to do add the remaining files in a new commit. This means that there are two separate commits although logically they are part of the same task.

The easiest way I know to include untracked files in the commit via two consecutive commands:

git add -A git commit -a -m "My commit message" 

Is it possible to have the same effect like the above in one command?

like image 330
Louis Rhys Avatar asked Apr 21 '13 04:04

Louis Rhys


People also ask

Does commit include untracked files?

Untracked basically means that Git sees a file you didn't have in the previous snapshot (commit), and which hasn't yet been staged; Git won't start including it in your commit snapshots until you explicitly tell it to do so.

How do I stash all untracked files?

In order to stash untracked files, add the “–include-untracked” option to your “git stash” initial command. Alternatively, you can simply use the “-u” which is equivalent to the untracked longer version.


1 Answers

Create a file in your execution path called (no extension): git-add-commit-untracked

Put this in it:

#!/bin/bash message=${0} git add -A git commit -am "$message" 

Then: git-add-commit-untracked "Commit message"

You can use a shorter name for the file though. I left it lengthy for illustrative purposes.

like image 94
d_ethier Avatar answered Sep 22 '22 16:09

d_ethier