Why does Git tell me "No such remote 'origin'" when I try to push to origin?
Solution 1
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
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
Solution 2
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.
Solution 3
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
Solution 4
The following steps work for me:
Init
First, initialize the repository to work with Git
, so that any file changes are tracked:
git init
Create alias origin
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 alias "origin":
git remote add origin https://github.com:/repo-owner/repo-name.git
and check to which URL, the remote alias "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)
Verify alias origin
Next, verify if your alias 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 must 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!
Pull any contents from remote main branch
$ git pull origin main
This will pull any contents you have on the repository you just aliased to origin
to the local repository, including .gitignore
, creating the branch main
in the process.
Check main branch
$ git branch
* main
This will show you that main
branch has been created and you are now on it.
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 my-super-git-repo
Finally
git add .
git status //If you want to check what's going to be committed
git commit -m 'First commit' //-m is for message
git push origin main
You will see a bunch of lines as follows:
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 8 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (21/21), 4.29 KiB | 292.00 KiB/s, done.
Total 21 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/repo-owner/repo-name.git
948279c..1f3b0b8 main -> main
Related videos on Youtube
Vijay
I am Vijay. I am working as a mobile app developer in a company. I would like to be a good software developer in future. I am a self learner. The biggest teacher and trainer for me is StackOverFlow and it's members.
Updated on July 08, 2022Comments
-
Vijay almost 2 years
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 error:
No such remote 'origin'
I ran the following commands:
git init git commit -m "first commit" git remote add origin https://github.com/VijayNew/NewExample.git git push -u origin master
However, when I ran git commit -m "first commit", I got the following message:
nothing added to commit but untracked files present (use "git add" to track)
So then I tried to set
origin
, usinggit remote set-url origin https://github.com/VijayNew/NewExample.git
But I got the following error:
No such remote 'origin'
What did I do wrong, and what should I do?
-
hek2mgl almost 10 yearsWhat gives you
git-remote -v
? -
Admin almost 10 yearsbetween the init and the commit add a "git add ." step. What output does "git remote" (or git remote -v") offer you?
-
Vijay almost 10 years
git remote -v
Nothing is Display. -
aymericbeaumet almost 10 yearsWell it seems the origin as not been properly saved then.
-
Vijay almost 10 years@aymericbeaumet.. What i have to do?
-
aymericbeaumet almost 10 years
git remote add origin ...
should suffice. Was there any error? -
Raja Simon almost 10 yearsdid you add 'git add' ?????
-
Vijay almost 10 yearsNow i am getting this error when i try to push
remote: Repository not found. fatal: repository 'https://github.com/VijayNew/NewExample.git/' not found
-
Vijay almost 10 yearsSure.. I just update my status. If it is wrong i am sorry @pqnet..
-
Raja Simon almost 10 yearshae vijay how did you clear the first error ?
-
Raja Simon almost 10 yearsi think again you need to add remote repository.. Come to chat. i ll help you
-
Vijay almost 10 yearsI just copy the project into another folder and try from the Beginning. Now i am struck with
remote: Repository not found.
-
Raja Simon almost 10 yearsoh ..! ok try delete the remote once and add again
-
Kemin Zhou over 7 yearsWhen you are starting a new repository, the first REMOTE command should be git remote add origin [email protected]:mygit, if you run git remote set-url origin [email protected]:mygit you will get error message: No such remote 'origin'. I run into the same problem, and it took a few minutes before I figure this out. Hope this can help others.
-
-
Vijay almost 10 years@ Jubobs. 1st prob is my mistake. Now i do like this.
git init git add --all git commit -m "first commit"
. Now it is working. 2) Actually i have deleted my account before 20 mins. Now I have created a new account.https://github.com/VijayMobileApp/WindowsPhoneExample.git
-
Vijay almost 10 yearsAnd still now i am getting
remote: Repository not found. fatal: repository 'https://github.com/VijayNew/NewExample.git/' not found
-
Raja Simon almost 10 years@Vijay you deleted your old account but still old account in use
-
Vijay almost 10 years
$ git remote set-url origin https://github.com/VijayMobileApp/WindowsPhoneExamp le.git fatal: No such remote 'origin'
-
jub0bs almost 10 yearsBy visiting the URL, I see that you've now created a repo called
WindowsPhoneExample
on your GitHub account,VijayMobileApp
. All you need to do now is rungit remote add origin https://github.com/VijayMobileApp/WindowsPhoneExample
. Then you should be able to push withgit push -u origin master
. -
jub0bs almost 10 yearsThis command only lets the local repo know about the remote one. It doesn't actually create the remote repo on the GitHub servers, which I think is what the OP needs to do here.
-
Vijay almost 10 yearsHi @Jubobs. Now it is working. At first I am also give this same url only. Then why it is not working for me. Now I am using url which is you give. Now it's working. Any way thank you Jubobs..!!
-
Emil Davtyan almost 10 yearsI'm well aware of what the command does. From the question I was guessing the user probably pasted all the commands at once and the commit failed so he never actually added the remote.
-
jub0bs almost 10 yearsJust to be clear, I wasn't suggesting that you don't know what
git remote add
does:)
Just that you didn't consider the possibility that the OP had never created the remote repo. -
sdjuan almost 6 yearsI had the same issue, and I had already created the remote repo. This answer was the solution.
-
Default almost 4 yearsThis is what I needed, the command line (set-url) was suggestion --add which didn't work at all. thanks
-
Igor Mironenko about 3 yearsThat did it for me - a little odd because I received the instruction to use
set-url
command from BitBucket's own instructions on "what to do next"