Jack
Jack

Reputation: 101

Adding a file to local git repository, then pushing to remote: doesn't work

I am very new to Git/github.

I set up a git repo (actually migrated from another version control system), and used:

/C/homedir

$ git init

I got now that /c/homedir is my master.

I pushed to my remote github server.

This pushed only the tracked files to the remote repo.

I added a new file to the local master repo in a subdirectory:

/C/homedir/somedir (master)

$ git add <file>
$ git commit -m "comment"

If I am in a subdirectory trying to push using:

/C/homedir/somedir (master)

$ git push origin master

it says

fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

And if I push to remote from the original directory:

/C/homedir/ (master)

$ git push origin master 

it says

Everything up-to-date

Question: How do I push the new file to the remote repo?


Edit: I have done the commit (forgot to write it; now fixed). Problem still persists.

Problem solved: a hidden .git file was present in the sub directory.

Upvotes: 0

Views: 1050

Answers (4)

Jack
Jack

Reputation: 101

Problem solved:

The crux of the matter is that there was an additional (hidden) .git file in the subdirectory \somedir !

This then caused the following:

If I am in a subdirectory trying to push using:

/C/homedir/somedir (master)

$ git push origin master

it says

fatal: 'origin' does not appear to be a git >repository fatal: Could not read from remote >repository. Please make sure you have the correct access rights and the repository exists.

Upvotes: 0

Charya
Charya

Reputation: 1

You missed one important step. The "commit" step. After adding the files, you need to commit these before pushing it to the remote repository.

git commit -m <description>

You may check out this link.

Upvotes: 0

Vahe Yavrumian
Vahe Yavrumian

Reputation: 558

At first, You always need to commit your changes after git add <file> with

git commit -m <short commit description here>

after that you don't need to push from your subdirectory, just go to the home directory and then push

git commit docs

Upvotes: 0

Alex
Alex

Reputation: 81

Probably you forgot to make a commit

git commit -m "my first commit"

https://git-scm.com/docs/gittutorial

Upvotes: 1

Related Questions