Genadinik
Genadinik

Reputation: 18639

New git repository error on first push

I did git init, then I realized I should include the link that I got when I made the repository in GitHub so I did this:

git init https://github.com/genadinik/AndroidMakeMoneyFree.git

Then I did:

git add -all
git commit -m "Adding repository contents"

And that worked fine, but then I tried to push and got this error:

git push origin master
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: 2

Views: 1094

Answers (4)

CodeWizard
CodeWizard

Reputation: 142084

Few options

  1. You do not have a remote.
    git init doesnt set the remote so you have to add it manually.

      git remote add origin https://github.com/genadinik/AndroidMakeMoneyFree.git
    
  2. You do not have ssh keys Generate ssh keys and change the remote url form HTTPS to ssh/git

You need to ssh keys:


Simply follow those steps and you will set up your ssh key in no time:

  • Generate a new ssh key (or skip this step if you already have a key)
    ssh-keygen -t rsa -C "your@email"

  • Once you have your key set in home/.ssh directory (or Users/<your user>.ssh under windows), open it and copy the content


How to add sh key to github account?

  • Login to github account
  • Click on the rancher on the top right (Settings)
    github account settigns
  • Click on the SSH keys
    ssh key section
  • Click on the Add ssh key
    Add ssh key
  • Paste your key and save

And you all set to go :-)

Upvotes: 0

Wader
Wader

Reputation: 9883

I don't think git init accepts a URL (although I could be wrong).

To add a remote repository run the following

git remote add origin https://github.com/genadinik/AndroidMakeMoneyFree.git

and for the first push you should use the following command to ensure all tags and such are pushed up.

git push -u origin --all

Upvotes: 1

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476594

As far as I know, you should not include the url of the GitHub (or other git server) repository in the git init. Git is distributed: you can add several remotes.

You initialize a git repository with:

git init

(optionally followed by the directory, if omitted, the current directory is used).

Then you can add a remote as follows:

git remote add origin https://github.com/genadinik/AndroidMakeMoneyFree.git

(or another url)

Here you add a remote you call origin. Mind that you can give it another name. You can also decide to add multiple remotes like GitHub, BitBucket, GitLabs, CodePlex,... and push your local copy to all of those remotes.

and then you can push to the origin or other remote.


If however GitHub already contains files, you better make a git clone, and work with the clone.

Upvotes: 4

Jacek Pietal
Jacek Pietal

Reputation: 2019

you must add origin repo

git remote add origin <url to repo>

see here https://help.github.com/articles/adding-a-remote/

Upvotes: 1

Related Questions