Question

I often find myself typing

git add -u

with the intention of adding everything that is modified but tracked in the whole repository. However, it gets annoying and tedious when I'm in a subdirectory. For example if all my modifications are in src/ but I'm currently in the test/util directory, then I need to type

git add -u ../..

which is error-prone and slow (because I need to compute the number of ../ in my head).

I would like to create a git alias au such that it automatically detects the toplevel (usually, the first ancestor directory in the path that contains the .git directory). It doesn't have to be perfectly portable, since I use git from bash. Any ideas?

Was it helpful?

Solution

No need to detect the top-level.
You can type in any subfolder:

git add -u :/

This is short for:

git add -u :(top)

See git glossary:

A pathspec that begins with a colon : has special meaning. In the short form, the leading colon : is followed by zero or more "magic signature" letters (which optionally is terminated by another colon :), and the remainder is the pattern to match against the path.

top: The magic word top (magic signature: /) makes the pattern match from the root of the working tree, even when you are running the command from inside a subdirectory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top