Table of contents

Git error fatal: No such remote 'origin'

Git Mar 24, 2020 Viewed 2.1K Comments 0

Question

On my computer, I run some commands to create git repository. 

$ mkdir test
$ cd test
$ git init
$ echo '' > index
$ git add index
$ git commit -m "init"

And I want to push to remote server. So I create an empty repository on server. Run it.

$ git init --bare --shared test.git
Initialized empty shared Git repository in /develop/git/test.git/

On my computer, I try to use set-url to modify the remote of the repository, and I get an error.

$ git remote set-url origin ssh://user@115.115.115.115/develop/git/test.git
fatal: No such remote 'origin'

Solution

When I running git remote -v, no addresses are displayed. So I need to add, not modify. Run:

$ git remote add origin ssh://user@115.115.115.115/develop/git/test.git

After running git remote -v again, I can see the links of fetch and push.

$ git remote -v
origin	ssh://user@115.115.115.115/develop/git/test.git (fetch)
origin	ssh://user@115.115.115.115/develop/git/test.git (push)

Then push to server.

$ git push --set-upstream origin master
Updated Mar 24, 2020