16

I get git-status at ~/bin:

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       screen/dev/

I run

git add --force screen/dev/

I get the same git-status as before. I add each file in the folder independently, but I get the same git-status.

There is no .git in screen/dev/. The folder seems not to be a sumbodule.

How can you add a folder and its content with force to my git at ~/bin?

Mononess
  • 312
  • 1
  • 6
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 2
    Can you reproduce this with a fresh Git repository, starting from "git init"? – Greg Hewgill Jul 15 '09 at 06:50
  • @Greg: I cannot reproduce the problem with a fresh Git repository, although I keep exactly the same names in the file structure. --- This suggests me that there must be some file in my repo which manipulates the folder screen/dev – Léo Léopold Hertz 준영 Jul 15 '09 at 22:10
  • I experienced the same problem on Windows. Turns out that I was adding the file "foobar.txt" when the filename was "Foobar.txt". Windows is case insensitive but Git still behaves as if it's running on Linux, so it treats files as case sensitive. – Mort Sep 12 '22 at 06:40

7 Answers7

10

You should not need '--force' or '-f' option: see git add:

-f
--force:

Allow adding otherwise ignored files.

In your case, you may not want to add all files, included ignored files under screen/dev directory.

 git add screen/dev

should be enough (without options or ending '/')

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
9

The problem can be solved by renaming the folder and adding the folder with a new name to Git.

This suggests me that there must be some file manipulating the folder name dev.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
6

Is that a typo on cut paste?

If not, it should be

git add --force screen/dev
Tyrone Slothrop
  • 40,787
  • 3
  • 17
  • 8
3

Try doing:

git add -A .

Also, if you have a .gitignore file it's also possible that you are unintentionally ignoring something (ie: possibly the files you are trying to add).

Fake Code Monkey Rashid
  • 13,731
  • 6
  • 37
  • 41
  • The same problem occurs also after running your command. I do not have the folder at the .gitignore -files. – Léo Léopold Hertz 준영 Jul 15 '09 at 16:35
  • 1
    This command doesn't make sense. `-A` and `.` do the same thing. No reason to combine both. See here: https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add?rq=1 – solidak Sep 26 '17 at 14:32
3

If nothing works...

  • Move the stubborn directory to a temp location outside the repo
  • Remove any remaining traces of the stubborn directory in the repo
  • Push and make sure that local is synced with remote
  • Move the stubborn directory from the temp location back to the repo (You don't have to rename)
  • git add -A
  • Commit and push
solidak
  • 5,033
  • 3
  • 31
  • 33
0

I've also found that you have to have at least a file in that dir in order to be picked up by git. git add screen/dev won't work if there are no files inside.

Deiu
  • 517
  • 5
  • 4
0

Just git add .

Take a break Have a KitKat Make a cup of coffee

and when you come back after a while it should be done

Leo
  • 1