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

319 questions
10374
votes
37 answers

How do I undo 'git add' before commit?

I mistakenly added files to Git using the command: git add myfile.txt I have not yet run git commit. Is there a way to undo this, so these files won't be included in the commit?
paxos1977
  • 143,025
  • 26
  • 88
  • 126
4884
votes
37 answers

How can I add a blank directory to a Git repository?

How can I add a blank directory (that contains no files) to a Git repository?
Laurie Young
  • 132,296
  • 13
  • 46
  • 54
3529
votes
116 answers

Message 'src refspec master does not match any' when pushing commits in Git

I clone my repository with: git clone ssh://xxxxx/xx.git But after I change some files and add and commit them, I want to push them to the server: git add xxx.php git commit -m "TEST" git push origin master But the error I get back is: error: src…
sinoohe
  • 35,636
  • 3
  • 17
  • 16
3259
votes
11 answers

Difference between "git add -A" and "git add ."

The command git add [--all|-A] appears to be identical to git add .. Is this correct? If not, how do they differ?
cmcginty
  • 106,318
  • 39
  • 155
  • 157
1357
votes
31 answers

Removing multiple files from a Git repo that have already been deleted from disk

I have a Git repo that I have deleted four files from using rm (not git rm), and my Git status looks like this: # deleted: file1.txt # deleted: file2.txt # deleted: file3.txt # deleted: file4.txt How do I remove these files…
Codebeef
  • 42,480
  • 20
  • 84
  • 117
969
votes
0 answers

How do I commit all deleted files in Git?

Possible Duplicate: Removing multiple files from a Git repo that have already been deleted from disk If I delete some files from the disk they come up as deleted like so in the Git repo: C:\git\bc>git status # On branch tracking2 # Changed but…
Igor Zevaka
  • 71,192
  • 26
  • 106
  • 127
739
votes
18 answers

Add all files to a commit except a single file?

I have a bunch of files in a changeset, but I want to specifically ignore a single modified file. Looks like this after git status: # modified: main/dontcheckmein.txt # deleted: main/plzcheckmein.c # deleted: main/plzcheckmein2.c ... Is…
user291701
  • 36,231
  • 70
  • 177
  • 280
567
votes
10 answers

Staging Deleted files

Say I have a file in my git repository called foo. Suppose it has been deleted with rm (not git rm). Then git status will show: Changes not staged for commit: deleted: foo How do I stage this individual file deletion? If I try: git add…
Andrew Tomazos
  • 61,784
  • 34
  • 168
  • 282
462
votes
11 answers

Fix GitLab error: "you are not allowed to push code to protected branches on this project"?

I have a problem when I push my codes to git while I have developer access in my project, but everything is okay when I have master access. Where is the problem come from? And how to fix it? Error message: error: You are not allowed to push code…
272
votes
10 answers

Git add all files modified, deleted, and untracked?

Is there a way to add all files no matter what you do to them whether it be deleted, untracked, etc? like for a commit. I just don't want to have to git add or git rm all my files every time I commit, especially when I'm working on a large product.
INSANENEIVIESIS
  • 2,741
  • 2
  • 15
  • 4
196
votes
11 answers

Adding Only Untracked Files

One of the commands I find incredibly useful in Git is git add -u to throw everything but untracked files into the index. Is there an inverse of that? Such as a way to add only the untracked files to the index without identifying them individually?
Rob Wilkerson
  • 39,088
  • 42
  • 133
  • 187
168
votes
5 answers

git add * (asterisk) vs git add . (period)

I'm new to git and I have a question about adding files in git. I have found multiple stackoverflow questions about the difference between git add . and git add -a, git add --all, git add -A, etc. But I've been unable to find a place that explains…
Tyler Youngblood
  • 2,310
  • 3
  • 16
  • 23
128
votes
6 answers

'git add --patch' to include new files?

When I run git add -p, is there a way for git to select newly made files as hunks to select?? So if I make a new file called foo.java, then run git add -p, git will not let me choose that file's content to be added into the index.
Alexander Bird
  • 35,595
  • 41
  • 120
  • 156
123
votes
13 answers

Undo git reset --hard with uncommitted files in the staging area

I am trying to recover my work. I stupidly did git reset --hard, but before that I've done only get add . and didn't do git commit. Please help! Here is my log: MacBookPro:api user$ git status # On branch master # Changes to be committed: # (use…
eistrati
  • 2,184
  • 6
  • 25
  • 35
117
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
  • 155,940
  • 141
  • 379
  • 495
1
2 3
21 22