Seth Nelson
Seth Nelson

Reputation: 2608

Git won't add any files - just an empty directory

I have been working on an iPhone project in Xcode, and decided I wanted to put it up on github. I created a repo on github, cloned it, and moved all my files into the directory. Then I attempted to

git add Directory .

I committed and pushed, and found that the only thing in the repo now was this directory. There is nothing in it - I can't even click it to open it in the github file viewer for the repo. It is a picture of a folder and the folder's name. I've tried

git add Directory .
git add Directory -A
git commit -a

Nothing will add these files to the directory. What am I doing wrong?

Upvotes: 3

Views: 6655

Answers (4)

joharr
joharr

Reputation: 535

Another repository may be present.

This was happening to me with plugin directories in my vimfiles. Reproduce like this:

  1. git clone something from GitHub (in my case, a plugin, eg vim-easymotion) somewhere into your repository (in my case into vimfiles\bundle)
  2. git add ., then git status will show that all that's been achieved is that the folder name (in this case bundle\vim-easymotion) has been added as a new file
  3. git commit, then git push origin master (pushing changes to GitHub)
  4. Navigate to GitHub in a browser to examine the folder that you had cloned something into in step 1, and you will see that it shows the clone's name as an empty file

I only realised what was going on when, from my vimfiles\bundle\vim-easymotion directory in Git Bash, I issued git config -l, and noticed a reference to Lokaltog, the owner of the vim-easymotion repository. So I issued git remote -v, and sure enough, in that directory the Git alias was origin https://github.com/Lokaltog/vim-easymotion.git, which is not my repository's remote address, but that of the plugin. Stunned at my ignorance, I navigated to the plugin directory with FreeCommander, showing hidden files and of course the plugin creator's .git files were there.

The cure, assuming you have cloned someone else's repository into yours, as I did:

  1. Git Bash in the offending cloned subdirectory, issue find . | grep /.git | xargs rm -rf to remove all of the unwanted .git files
  2. git remote -v to check that you're back to your own remote's alias
  3. Now temporarily move the whole of that subdirectory out of your repository
  4. git status will now report that a file has been deleted (in my case vim-easymotion)
  5. git add -A to stage that deletion, then git commit, and git push origin master to remove that daft filename from your remote at GitHub
  6. Move the (now clean) subdirectory back into your repository, and continue as normal.

Upvotes: 8

Jack O'Connor
Jack O'Connor

Reputation: 10886

I'm surprised to hear that git add . ; git commit is not working for you. Are you sure you're running those commands from the topmost directory in your repo? Here's a summary of what you would normally expect to happen:

cd ~/Directory  # or whatever the path is in your case
git status      # shows lots of "Untracked files" because this is a new repo
git add .       # adds everything to your index
git status      # now shows lots of "Changes to be committed"
git commit      # fires up the editor and finishes the commit
git show        # shows the commit you just made

At what point does this break down for you?

Upvotes: 1

kgr
kgr

Reputation: 9948

git add .

while in the Directory should add everything inside, unless it is ignored by your .gitignore file...

Upvotes: 2

patthoyts
patthoyts

Reputation: 33203

Try git add . or perhaps use git gui and select the files in that by clicking the icons to stage them then commit.

git doesn't track directories - it tracks the files and directories get to come along for the ride. If you add the files explicitly the directory will be included as part of the file path. To add a directories contents git add Directory/* would do the job.

Upvotes: 1

Related Questions