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
11151
votes
38 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. How do I undo this so that these changes will not be included in the commit?
oz10
  • 153,307
  • 27
  • 93
  • 128
5251
votes
37 answers

How do I add an empty directory to a Git repository?

How do I add an empty directory (that contains no files) to a Git repository?
Laurie Young
  • 136,234
  • 13
  • 47
  • 54
3997
votes
137 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
  • 40,334
  • 3
  • 19
  • 16
3415
votes
12 answers

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

What is the difference between git add [--all | -A] and git add .?
cmcginty
  • 113,384
  • 42
  • 163
  • 163
1384
votes
32 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
  • 43,508
  • 23
  • 86
  • 119
969
votes
0 answers

How do I commit all deleted files in Git?

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 not updated: # (use "git add/rm ..." to update what will be committed) # (use "git checkout --…
Igor Zevaka
  • 74,528
  • 26
  • 112
  • 128
828
votes
19 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
  • 38,411
  • 72
  • 187
  • 285
618
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
  • 66,139
  • 40
  • 186
  • 319
576
votes
16 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 code 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 to…
325
votes
12 answers

What does "Changes not staged for commit" mean

I thought if you want to track the files you should git add [files you want to track] I don't know why I got the messages Changes not staged for commit. If those files were not staged, shouldn't git shows me those files were Untracked like…
newBike
  • 14,385
  • 29
  • 109
  • 192
278
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,801
  • 2
  • 17
  • 4
205
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
  • 40,476
  • 42
  • 137
  • 192
194
votes
5 answers

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

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 what git add * does.…
Tyler Youngblood
  • 2,710
  • 3
  • 18
  • 24
140
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
  • 38,679
  • 42
  • 124
  • 159
131
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,314
  • 6
  • 26
  • 35
1
2 3
21 22