Questions tagged [git-add]

git-add - Add file contents to the index

Before each commit in , you need to add file contents to the staging area.

The following will add all the files currently on the stage at the next commit:

$ git add .

This also adds the files recursively under the current working directory. Files previously tracked (i.e. they were in the last commit), still need to be added to the stage.

You can track new files specifically like so (where foo is the filename in this example):

$ git add foo

To add multiple files, separate them with a space like so (bacon and cheese being the other example files):

$ git add foo bacon cheese

References

330 questions
122
votes
3 answers

git add . vs git commit -a

What's the difference between: git add . git commit -a Should I be doing both, or is that redundant?
Yarin
  • 173,523
  • 149
  • 402
  • 512
109
votes
9 answers

Git add all subdirectories

I'm having trouble adding a folder and all of it's subdirectories to my git repository. I realized this is a very popular question after doing some googling and I've tried each suggestion with no luck, specifically the suggestion from the man page…
Josh Bradley
  • 4,630
  • 13
  • 54
  • 79
103
votes
2 answers

Undo git add --all

I made a mistake and called git add -all, now all files are added. I did not make a commit and push. How can I undo my action?
BendEg
  • 20,098
  • 17
  • 57
  • 131
98
votes
13 answers

git add --interactive "Your edited hunk does not apply"

I'm trying to use git add --interactive to selectively add some changes to my index, but I continually receive the "Your edited hunk does not apply. Edit again..." message. I get this message even if I choose the e option, and immediately…
Josh
  • 2,077
  • 1
  • 17
  • 21
86
votes
4 answers

How do I remove a directory subtree from the staging area?

I made a new repository, and ran git add -A. I then noticed that there was a folder containing about 100 files that shouldn't have been included, so I added it to .gitignore. How do I now clear the staging area so that I can add all my files again…
Acorn
  • 49,061
  • 27
  • 133
  • 172
83
votes
4 answers

What does the 'git add .' ('git add' single dot) command do?

I don't get what the Git command means, when adding files to the stage with the use of a period (or full stop, single dot): $ git add . What does this do?
chunjw
  • 919
  • 1
  • 8
  • 8
77
votes
3 answers

What's the difference between `git add .` and `git add -u`?

I was assuming that both work in the same way. Both add every file onto index. But I seem wrong. What's the difference between git add . and git add -u?
TK.
  • 27,073
  • 20
  • 64
  • 72
75
votes
8 answers

Stage only deleted files with git add

I have run git status and see several modified files and several deleted files. Is it possible to stage only deleted or only modified files?
rok
  • 9,403
  • 17
  • 70
  • 126
66
votes
6 answers

How to avoid specifying absolute file path while git-add

Using git add command becomes tedious once the file path becomes lengthy. For e.g. git add src_test/com/abc/product/server/datasource/manager/aats/DSManger.java Is it possible to bypass specifying absolute file path? May be using some kind of…
Vaman Kulkarni
  • 3,411
  • 2
  • 21
  • 22
64
votes
15 answers

GitHub - error: failed to push some refs to 'git@github.com:myrepo.git'

I ran these commands below: git add . git commit -m 't' Then, when running the command below: git push origin development I got the error below: To git@github.com:myrepo.git ! [rejected] development -> development…
Tampa
  • 75,446
  • 119
  • 278
  • 425
62
votes
13 answers

github changes not staged for commit

I have a very basic github setup with a readme, a directory, and another directory inside it with an html file. On github I can only view the readme and the first folder but none of its contents, and I am getting this message tc349 ryntc3$ git add…
Ryan Tice
  • 731
  • 3
  • 13
  • 16
61
votes
6 answers

git: How do I recursively add all files in a directory subtree that match a glob pattern?

I have several .screen files inside /xxx/documentation and its subdirectories that are already tracked by Git. After modifying many of these screen files, I run git add documentation/\\*.screen—as indicated by the first example in git-add's…
Phương Nguyễn
  • 8,747
  • 15
  • 62
  • 96
51
votes
4 answers

How to do 'git checkout --theirs' for multiple files (or all unmerged files)

Say I have this after attempting a merge and upon entering git status: # Unmerged paths: # (use "git add/rm ..." as appropriate to mark resolution) # # added by them: myfile1.xhtml # added by them: myfile2.xhtml # added by them:…
isherwood
  • 58,414
  • 16
  • 114
  • 157
47
votes
4 answers

hg equivalent of git add -p?

Is there a mercurial equivalent of git add -p? Quoting from man, git-add with the option -p (or --patch) does the following: Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a…
andreliebschner
  • 535
  • 4
  • 7
46
votes
4 answers

why `git diff` reports no file change after `git add`

 Why is that git diff thinks there are no changes ..even if git status reports them as modified? $ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) Changes to be…
eridal
  • 1,288
  • 1
  • 11
  • 23
1
2
3
21 22