Why does Git tell me “No such remote 'origin'” when I try to push to origin?

前端 未结 4 1488
清歌不尽
清歌不尽 2021-01-29 21:09

I am very new to Git; I only recently created a GitHub account.

I\'ve just tried to push my very first repository (a sample project), but I\'m getting the following erro

相关标签:
4条回答
  • 2021-01-29 21:20

    I'm guessing you didn't run this command after the commit failed so just actually run this to create the remote :

     git remote add origin https://github.com/VijayNew/NewExample.git
    

    And the commit failed because you need to git add some files you want to track.

    0 讨论(0)
  • 2021-01-29 21:23

    I faced this issue when I was tring to link a locally created repo with a blank repo on github. Initially I was trying git remote set-url but I had to do git remote add instead.

    git remote add origin https://github.com/VijayNew/NewExample.git
    
    0 讨论(0)
  • 2021-01-29 21:34

    Two problems:

    1 - You never told Git to start tracking any file

    You write that you ran

    git init
    git commit -m "first commit"
    

    and that, at that stage, you got

    nothing added to commit but untracked files present (use "git add" to track).
    

    Git is telling you that you never told it to start tracking any files in the first place, and it has nothing to take a snapshot of. Therefore, Git creates no commit. Before attempting to commit, you should tell Git (for instance):

    Hey Git, you see that README.md file idly sitting in my working directory, there? Could you put it under version control for me? I'd like it to go in my first commit/snapshot/revision...

    For that you need to stage the files of interest, using

    git add README.md
    

    before running

    git commit -m "some descriptive message"
    

    2 - You haven't set up the remote repository

    You then ran

    git remote add origin https://github.com/VijayNew/NewExample.git
    

    After that, your local repository should be able to communicate with the remote repository that resides at the specified URL (https://github.com/VijayNew/NewExample.git)... provided that remote repo actually exists! However, it seems that you never created that remote repo on GitHub in the first place: at the time of writing this answer, if I try to visit the correponding URL, I get

    enter image description here

    Before attempting to push to that remote repository, you need to make sure that the latter actually exists. So go to GitHub and create the remote repo in question. Then and only then will you be able to successfully push with

    git push -u origin master
    
    0 讨论(0)
  • 2021-01-29 21:43

    The following simple steps help me:

    First, initialize the repository to work with Git, so that any file changes are tracked:

    git init
    

    Then, check that the remote repository that you want to associate with the alias origin exists, if not create it in git first.

    $ git ls-remote https://github.com/repo-owner/repo-name.git/
    

    If it exists, associate it with the remote "origin":

    git remote add origin https://github.com:/repo-owner/repo-name.git
    

    and check to which URL, the remote "origin" belongs to by using git remote -v:

    $ git remote -v
    origin  https://github.com:/repo-owner/repo-name.git (fetch)
    origin  https://github.com:/repo-owner/repo-name.git (push)
    

    Next, verify if your origin is properly aliased as follows:

    $ cat ./.git/config
    :
    [remote "origin"]
            url = https://github.com:/repo-owner/repo-name.git
            fetch = +refs/heads/*:refs/remotes/origin/*
    :
    

    You need to see this section [remote "origin"]. You can consider to use GitHub Desktop available for both Windows and MacOS, which help me to automatically populate the missing section/s in ~./git/config file OR you can manually add it, not great, but hey it works!

    [Optional]
    You might also want to change the origin alias to make it more intuitive, especially if you are working with multiple origin:

    git remote rename origin mynewalias
    

    or even remove it:

    git remote rm origin
    

    Finally, on your first push, if you want master in that repository to be your default upstream. you may want to add the -u parameter

    git add .
    git commit -m 'First commit'
    git push -u origin master
    
    0 讨论(0)
提交回复
热议问题