2

I am trying to push all my new files to a Github repo. However, it puts all the changed files in a new directory.

Example:

$ cd foobar
$ git add foo.txt
$ git add bar.txt
$ git add bax.txt
$ git commit -m "change some files"
$ git push origin master

Then I go to my Github repo, say, foobarbaz. Instead of all my changes going into the repo, a new folder is made called foobar. This folder contains all the files I added to the commit. Why is this?

Edit: "foobar" is the root dir of the repo (I know that it is too late to make this edit, but I thought new visitors should know)

Ateur Games
  • 79
  • 1
  • 11
  • is this a new repository you initialized or a cloned repository? My hunch is that this is a new repository you initialized using `git init` and you might have done `git init` from the parent of `foobar` directory (so `.git` folder is inside the parent) but did everything else (git add, commit etc.) after cd into foobar. Is this correct ? – rubyprince Dec 12 '19 at 01:52

3 Answers3

1

Try and check your root folder for this local repository

cd .. # parent folder of foobar
git ls-files

If this works and you see:

foobar/foo.txt
foobar/bar.txt
...

That would illustrates the root folder is not foobar, but its parent folder.
See also "Is there a way to get the Git root directory in one command?"

git rev-parse --show-toplevel

That should show you where the root folder is.

You would need to recreate a .git/ (git init) inside foobar, to get the proper result.
Then add the remote:

git remote add origin /url/remote/repository
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

There is nowhere in the command you used where you used the foobarbaz rather I see you changed directory to foodbar and staged the text file food, bar and bax. I will suggest you check the name of repository you are using.

Torch
  • 51
  • 1
  • 9
0

Apperantly .git somehow moved out of my root dir. I have no idea how this happened, but a quick cut/paste did the trick.

Ateur Games
  • 79
  • 1
  • 11