Its my Code Blog

What exactly does git add -A do?

December 02, 2015

alt text

Simple git workflow

When working on my personal projects I have always followed a simple git workflow that involves nothing more complicated than creating a new branch adding and comitting my changes into the new branch, then merging the new branch into master and pushing it to bitbucket or github.

git branch "NewBranch"
...make changes....
git add -A
git commit -m "Added changes"
git checkout master
git merge NewBranch
git push

What does git add -A actually do?

Git Version 1.x

In git version 1.x git add -A is a shorthand way of typing the git add --all command that stages (adds) all new, modified and deleted files. This is in itself a shorthand way of typing the commands

git add .
git add -u

where git add . stages new and modified files only and git add -u stages modified and deleted files only.

# For the next commit
$ git add .   # stage only files new or modified files 
$ git add -u  # stage only files modified or deleted files 
$ git add -A  # stage files new, modified or deleted files 

Git Version 2.x

In git version 2.x the git add commands have changed so that git add . is now equivalent to git add -A

# For the next commit
$ git add .   # stage files new, modified or deleted files 
$ git add -u  # stage only files modified or deleted  files 
$ git add --ignore removal  # stage only new or modified files 
$ git add -A  # stage files new, modified or deleted

So, when I upgrade from git 1.x to 2.x I will be able to save typing one character by using git add . instead.


Nicholas Murray
Stuff I've learnt and stuff I like