34

this is my repository https://github.com/kiotie32/artbit-text.git when I do

$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/kiotie32/arbit-text.git/' not found

I am on a Windows 10 machine. I had configured ssh keys to be used with this laptop. I do an ls and I can see

 MINGW64 ~/.ssh
$ ls
kiotie32_rsa  kiotie32_rsa.pub  known_hosts

I read all the answers given on this thread I changed the password stored in windows credential manager.

I check git remote -v | head -n1 | awk '{print $2}' | sed 's/.*\///' | sed 's/\.git//' I get following output arbit-text

I changed the password stored in windows credentials manager probably an old password was stored.

I do not get any popup asking username password. (an ssh key was configured but not sure if that is working on this Windows 10 environment I have the key stored in .ssh in git bash) Now I do

$ git remote add origin https://github.com/kiotie32/arbit-text.git
fatal: remote origin already exists.

then I do

$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/kotie32/arbit-text.git'

So I am not able to understand why this error is coming/

I tried the solution here https://stackoverflow.com/a/7572252/13012032 first answer to do
git commit -m "initial master"
and then I got
$ git push origin master remote: Repository not found. fatal: repository 'github.com/kotie32/arbit-text.git' not found
then I tried as in comments
git add -all and then I did
$ git push origin master remote: Repository not found. fatal: repository 'https://github.com/kotie32/arbit-text.git/' not found

then from another answer https://stackoverflow.com/a/4183856/13012032 I tried
$ git show-ref 79d1730e9aa78f68a11ec4de6a0e8d6b66f17afb refs/heads/master
then I did
$ git push origin HEAD:master remote: Repository not found. fatal: repository 'https://github.com/kotie32/arbit-text.git/' not found

I notice in the last error on above url spelling kotie32 is wrong it should be kiotie32 checkd the config file inside the .git folder and there I see the following

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/kiotie32/arbit-text.git
        fetch = +refs/heads/*:refs/remotes/origin/*

so here url is corrrect the spelling is kiotie32 which is correct.

ok I now noticed that 2 directories have formed. project folder/.git/.git and config file of <project folder>/.git has wrong url and the inner one i.e. <project folder>/.git/.git has correct url.

I changed the config file of <project folder>/.git and deleted subdirectory .git/.git the new config file has

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = https://github.com/kiotie32/arbit-text.git
        fetch = +refs/heads/*:refs/remotes/origin/*

and then I again do

$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/kiotie32/arbit-text.git/' not found

then I did

$ git remote set-url origin https://github.com/kiotie32/artbit-text.git

then now I am able to push to master branch.

koeradoera
  • 507
  • 1
  • 4
  • 9
  • Does this answer your question? [Message 'src refspec master does not match any' when pushing commits in Git](https://stackoverflow.com/questions/4181861/message-src-refspec-master-does-not-match-any-when-pushing-commits-in-git) – phd Mar 12 '20 at 20:19
  • https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+src+refspec+master+does+not+match+any – phd Mar 12 '20 at 20:19
  • I tried the solution given on your first link's first answer to do `git commit -m "initial master" and then I got `$ git push origin master remote: Repository not found. fatal: repository 'https://github.com/kotie32/arbit-text.git/' not found` then I tried as in comments `git add -all` and then I did `$ git push origin master remote: Repository not found. fatal: repository 'https://github.com/kotie32/arbit-text.git/' not found ` – koeradoera Mar 12 '20 at 20:25
  • https://stackoverflow.com/a/43525596/7976758, https://stackoverflow.com/search?q=%5Bgit%5D+remote%3A+Repository+not+found – phd Mar 12 '20 at 20:28
  • Does this answer your question? [git error: failed to push some refs to](https://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to) – Enlico Mar 29 '20 at 17:26
  • I by now deleted every thing and did every thing again from scratch I don't remember what errors came when I posted the question. Things are working fine on my laptop as of now. – koeradoera Mar 29 '20 at 20:25
  • Maybe there is no `master` branch, test `main` :D – hamid Mahmoodi Nov 08 '21 at 19:54

23 Answers23

44

I had the same problem but this command resolved it.

Replace:

git push -u origin master

with following command:

git push -u origin main

or

git push -f origin main
SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
41

Just give a try to the following command:

git push origin master --force
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Arun Kumar N
  • 1,611
  • 1
  • 20
  • 25
  • 3
    No that was not the problem by the time you answer I posted question on 12 march 2020 you answered 19/5/2020 , I already gave a solution in my question as how I solved. The problem was I had two .git folders one folder was inside another git and also the remote repository link was wrong so I deleted them and again did all things from scratch. Then it worked – koeradoera May 18 '20 at 22:23
18

check maybe you are trying to push without commiting. try to commit you changes.

git commit -m "my commit"

or type git branch to see if you have set the remote url. if nothing shows up, then add the remote origin url git remote add origin https://github.com/username/projectname.git. then try git push origin master

bimeri noel
  • 191
  • 1
  • 2
6

This helped me.

git push origin master:main

Which master is my local branch and main is my remote branch. I think this happened because Github renamed master to main

Reza
  • 845
  • 13
  • 18
5
  1. Try doing a commit command.

git commit -m "first commit"

  1. Stage all files or select specific files.

git add .

  1. Check the status of the files.

git status

  1. Push the code to your repository.

git push origin main (or whatever is the name of your main or master branch).

minTwin
  • 1,181
  • 2
  • 21
  • 35
4

it's work on my case

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

add your mail and name of github

Abdallah
  • 79
  • 1
  • 7
3

Usually I get this error message when trying to git push command. Run the following command:

git add --all

Then:

git push -u origin main
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Sahana
  • 31
  • 1
2

This error could have occured in following scenarios as well

  1. If you have changed your github username, password or email
  2. If you are trying to push commits to someone else's branch while your windows is configured with your github credentials

I have got this error in above scenarios, and this is how i solved it

  1. Deleted github credentials stored in Credential Manager in Windows

  2. After that, I tried to push my commits again with following command, and then it prompted me to enter github credentials. (if you are pushing to someone else's repo, make sure that you enter the credentials of that github user's account

    git push -u (repo-url) (branch-name)

2

One more thing (just in case this may help somebody in the future): You gotta have a commit to push.

LuisE
  • 553
  • 3
  • 18
2

Actually this is happen due to change credential of Github Account

For example your gitbash is synchronize to 'A' account Repositery in past from you pull or push but you at this time you are to push or pull 'B' account Repositery. It mean you are try to push or pull Repositery which is blong to other Account Not Old Account. At this time this exception (error'failed to push some refs to 'https://github.com/') will be rise.

Actually OS (linux or windows) store your account authentication in credential Manager of Old account. When you push or Pull from account 'B' Repo(new account).

Gitbash authenticate your Account 'B' (new Account) with Credential of Account 'A' (Old Account) which is store in OS credential Manager. than Rise this Error.

Solution

  1. in Windows Search Bar type 'Credential Manager'

How to Open Credential manager

2. Open Credential Manager 3. Click on Windows Credential

How to Open windows Credential Manager

  1. "Click On git:https://GitHub.com"

How to Remove Github Credential

  1. After Remove the credential. You Will push it will asked new account Details As it authenticate you code will be push or pull.

  2. if your could not pull or push than you set

your are email and your name and than push

git config  user.email 'xxxx@gmail.com'
git config user.name 'xxxxx'

and again push

git push -u origin branch_name

Thank you for Asking

2
git push -u origin HEAD:master
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
ZUBER
  • 21
  • 1
  • 4
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 19 '21 at 06:44
  • 2
    Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/349538) would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you’ve made. – helvete Oct 19 '21 at 08:40
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: https://stackoverflow.com/help/how-to-answer . Good luck – nima Oct 20 '21 at 12:22
1

You are seeing that error because your local git repo is still empty. Make some commits and its all going to work perfectly.

Joseph Ajibodu
  • 1,093
  • 10
  • 14
1

I encountered a similar situation but in my case, i had a local repository which i had to connect with the remote repo.

This is how i solved it,

  • Create repo online via github and copy its address (use the same name as local folder )
  • CD to the local git repo and add remote git remote add origin [add remote repo address]
  • Check the local working branch chances are you may be working on master or main
  • Commit and push to the relevant branch git push origin master
Najim
  • 11
  • 1
0

I faced the same error. Then, I realized that original branch is not call original anymore. Then, I tried this code and it worked:

git push origin main

just replace master with main.

milad
  • 204
  • 3
  • 12
0

Just for anyone else, if you are experiencing this error, probably,

  • You are not in the main directory that has your repo on your computer.

Or

-you have not added or committed your changes

Just a tip.

jovialcore
  • 601
  • 1
  • 5
  • 13
0

I faced same problem and I perform following command

git add --all

this cmd add all file and then commit is done

git commit -m [message]

then finally I was able to push by performing

git push -u origin main

hope that works for you too

Minus
  • 11
  • 1
  • 4
0

This Worked for me!

git push --set-upstream origin main
A_Mo
  • 338
  • 2
  • 8
0

This problem happens when you had another remote origin in the folder you trying to send to a fresh repo. This worked for me:

rm -rf .git/

git init

git add -A

git push -u origin main
0

git add .


git commit -m "message"


git push -f

Ahmed Raza
  • 401
  • 4
  • 6
-1

Try to do:

git pull origin repo-name 

than try:

git push origin repo-name
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
-1

If nothing works,

just check the status of the commit .

> git status

if the code is not added into the staging area, do

git add .

check the git status

git status

commit the code and take the snapshot

> git commit -m "your message here"

Forcefully push the code which overrides the existing code and mismatches.

git push -f

sanket bisne
  • 29
  • 1
  • 3
  • 1
    This question is over 2 years old and already has 25 answers. Are you _entirely sure_ that this answer introduces something new? Doesn't [this answer](https://stackoverflow.com/a/70510806/354577) already cover everything above? Please don't repeat answers, and especially when answering old questions with existing answers please make sure to explain how your answer is different from, and ideally better than, existing ones. – ChrisGPT was on strike Jul 09 '22 at 14:46
-2

Please check your current branch if you are in not a master branch then try this command:

git branch master

this change our current branch to master branch. Finally do

git push -u origin master
Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
  • `git branch master` does not "*change our current branch to master branch*" It will try to create a master branch, but you will still be in the same branch. – Gino Mempin Jul 16 '21 at 00:01
-2

In my case changing master to main works .

git push -u origin main
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • This is the same solution as in [this other answer](https://stackoverflow.com/a/65299575/2227743). *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Sep 28 '21 at 10:57