Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This has caught me up a couple times. I have a terminal open inside a GIT repository. I do git status to see all the changes across the repository. I then do git add -A, git commit -m "Some text" and git push to push everything to GitHub.

But... I fail to realise that my terminal's working directory is not the repository's root directory, so actually, git add -A does not commit all changes git status told me about, only the changes to files inside the terminal's working directory.

How can I git add from within a GIT repository (not necessarily having the root directory as working directory) so that it will add all changes across the repository?

share|improve this question
BTW, beginning with Git 2.0, git add -A and git add -u will start operating on the entire tree for consistency with other commands. So say the Git 1.8.2 release notes. – jjlin Mar 14 '13 at 5:31
up vote 6 down vote accepted

You can use git add -A :/.

A pathspec which starts with a colon tells git that it should interpret the remainder of that pathspec from the base of the repository rather than from the current directory. Followed by just a slash it will refer to the root of the repository, causing git add to add all changes.

This appears to require git 1.7.6 or newer.

share|improve this answer
Didn't work: fatal: pathspec 'server/:' did not match any files – Randomblue Feb 12 '13 at 15:08
What OS are you using? Windows perhaps? It sounds like the colon is being handled by something other than git. That command works on Linux. There may be a way to quote the argument on your OS. – qqx Feb 12 '13 at 15:10
I'm using RedHat Enterprise Linux 6. – Randomblue Feb 12 '13 at 15:35
I take back the bit about it being some OS issue. I'am able to get that same type of error message by adding some random characters after the colon. Does it work if you use :. (colon followed by dot) in place of the lone :? – qqx Feb 12 '13 at 15:42
As I've noted in an edit of the answer, this appears to require version 1.7.6 of git. I believe that RHEL6 ships with 1.7.1, so it wouldn't support this syntax. – qqx Feb 12 '13 at 16:10

git commit -a -m commit_msg will do what you want. Note that with this command, the -a flag does the adding, so don't do a separate git add before the commit.

share|improve this answer
commit -a won't add new files to the repository, only all changes to already tracked files. It also won't remove files from the repository which have been removed from the working tree like add -A will do. – qqx Feb 12 '13 at 14:58
One difference to be aware of here is that git add -A will add untracked files, whereas git commit -a only adds changed files. Also git add -A will remove missing files from the index. – Drew Noakes Feb 12 '13 at 14:59
@qqx, you can do a git add ...., the git commit -am "My message" will pick them up. – vonbrand Feb 13 '13 at 3:41

Since my other answer requires a newer version of git, here's an alternative that will hopefully work with older versions.

Aliases where the expansion starts with an exclamation mark are treated as separate shell commands, and they are defined as executing in the top level of the repository. So you could define such an alias and use that in place of git add:

git config --global alias.addroot '!git add'
git addroot -A

Or you could include the -A option in the alias.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.