14

I created a remote repo then create a local one locally:

git init

then added the files i need using git add then git commit -m "something"

finally git push origin master

I got this error 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.

should i like the remote and local in some command or something? and if so is it ok if i already added and commited or should i start over locally?

EDIT:

Apparently i should add git remote add origin ssh://git@example.com:1234/myRepo.git but what should i replace that ssh with as in where can i find my version of what i should add.

Got this error :

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Kelly
  • 153
  • 1
  • 2
  • 8
  • 1
    Possible duplicate of [git: updates were rejected because the remote contains work that you do not have locally](https://stackoverflow.com/questions/24357108/git-updates-were-rejected-because-the-remote-contains-work-that-you-do-not-have) – phd Jul 11 '18 at 07:48
  • 1
    Possible duplicate of [Setting up a git remote origin](https://stackoverflow.com/questions/7259535/setting-up-a-git-remote-origin) – Liam Jul 11 '18 at 07:51

8 Answers8

31

When you run git clone <repo_url> to clone a repository, the default remote origin is created automatically. If the repository is created by git init, there is no default remote, no origin. You need to set it up by yourself.

git remote add origin <repo_url>

repo_url is the path to an existing remote repository which you want to exchange data with . If it's in the local disk, it could be file:///home/me/foo.git or /home/me/foo.git. If it's hosted in Github, it could be https://github.com/me/foo.git or ssh://git@github.com/me/foo.git.

As to the 2nd error about "fetch first". You need to run git pull origin <branch> or git pull -r origin <branch> before a next push.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • on doing this which way is the data going I have mine locally and do not want to over write them doing it the wrong way around! – Dave May 13 '21 at 13:21
8

try this

git remote add origin <https://github.com/"username"/"repository".git> 

then try to again

git push -u origin master
5
git remote add origin <url>

then

git push -u origin master
shaher11
  • 130
  • 1
  • 7
2

I had this same error message while trying to do a PR. On a critical look, I realized I was carrying out the Git workflow on a wrong directory.

In my case, I simply went back a step to the right dir using **cd..** and then proceeded with no more error.

Okpo
  • 375
  • 4
  • 9
0

Run below command

git remote add origin git@github.com:xxxx/xxxx.git

no SSH please!

Jaimil Patel
  • 1,301
  • 6
  • 13
Jackson
  • 71
  • 1
  • 6
0

first you need to run this command:

git remote add origin https://github.com/"USERNAME"/"REPOSITORY_NAME".git

after that this:

git push -u origin "branch name"

This will work !!!

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Ankush Chauhan
  • 151
  • 1
  • 4
0

I got the following error when I tried to upload the code with git push origin <branch> command:

fatal: 'orgin' 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.

try this

git remote add origin <https://github.com/"username"/"repository".git>

then try to again

git push -u origin master

I took a reference from this programmer: Hồ Kim Long Sơn

-2

This happens because your config file contains master word instead of heroku git url. This might happen when you initialize git more than once.

  1. Edit the config file

    git config --e

  2. Then edit master word to heroku url e.g. https://git.heroku.com/project_name.git

  3. Save it wq!

  4. Then push update by git push heroku master

I hope this will help you!

Ally Makongo
  • 269
  • 5
  • 14