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

299 questions
4623
votes
36 answers

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

How can I add an empty directory (that contains no files) to a Git repository?
Laurie Young
  • 129,506
  • 13
  • 44
  • 54
3113
votes
12 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
  • 101,562
  • 37
  • 148
  • 155
1339
votes
30 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
  • 41,810
  • 20
  • 83
  • 116
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
  • 69,206
  • 26
  • 104
  • 125
670
votes
15 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
  • 34,331
  • 68
  • 176
  • 277
536
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
  • 58,923
  • 32
  • 156
  • 267
413
votes
10 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…
268
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,701
  • 2
  • 14
  • 4
182
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? In the last few months, I've often found myself in a position where I've interactively added some…
Rob Wilkerson
  • 37,910
  • 41
  • 130
  • 185
152
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,090
  • 3
  • 14
  • 22
119
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,134
  • 6
  • 25
  • 35
113
votes
5 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
  • 33,259
  • 40
  • 118
  • 154
111
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
  • 144,097
  • 139
  • 361
  • 489
89
votes
8 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,310
  • 11
  • 49
  • 78
88
votes
12 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
  • 1,895
  • 1
  • 14
  • 21
1
2 3
19 20