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


325 questions
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?
  • 147,191
  • 27
  • 92
  • 126
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
  • 134,006
  • 13
  • 47
  • 54
126 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…
  • 38,086
  • 3
  • 18
  • 16
12 answers

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

What is the difference between git add [--all | -A] and git add .?
  • 109,252
  • 39
  • 158
  • 160
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…
  • 42,820
  • 21
  • 85
  • 118
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
  • 72,640
  • 26
  • 109
  • 127
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…
  • 37,221
  • 71
  • 183
  • 282
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
  • 63,609
  • 36
  • 177
  • 297
13 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…
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…
  • 13,845
  • 27
  • 104
  • 173
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.
  • 2,761
  • 2
  • 16
  • 4
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,838
  • 42
  • 135
  • 189
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,450
  • 3
  • 17
  • 23
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, then run git add -p, git will not let me choose that file's content to be added into the index.
Alexander Bird
  • 36,952
  • 42
  • 124
  • 156
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…
  • 2,284
  • 6
  • 26
  • 35
2 3
21 22