Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stage all changes in git from with a repo subdirectory

Tags:

git

So the command to stage all changes for git is git add -A.

Is there a way to execute this from within a repository subdirectory, and capture all changes anywhere in the repo, without having change the directory back to the repo root?

Example:

$pwd
/reporoot/

modify the file: /reporoot/a-file

$cd /a-subdir

$git 'magic variation of add -A which I'm looking for'

and the change to /reporoot/a-file will be staged.

I find that I'm often in one place in the terminal, but editing a file somewhere else with the IDE, so the answer to this question would be a helpful way for avoiding lots of cd'ing.

like image 539
Shaun Dychko Avatar asked Feb 26 '12 22:02

Shaun Dychko


2 Answers

Use the following (only works in newer versions of Git):

git add $(git rev-parse --show-toplevel)

You may wish to create a Git alias for this to make running it easier.

Note that, if you plan on committing, doing the following will stage all changed files already in the working tree (i.e., not untracked files):

git commit -a
like image 64
Andrew Marshall Avatar answered Nov 09 '22 00:11

Andrew Marshall


You are looking for git add -u, see the nice explanation here Difference between "git add -A" and "git add ." or the manual http://git-scm.com/docs/git-add . If you are going to commit next anyway, use git commit -a as mentioned by Andrew.

like image 29
Echsecutor Avatar answered Nov 08 '22 22:11

Echsecutor