I just started using git with github. I followed their instructions and ran into errors on the last step. I’m checking in an existing directory that isn’t currently source-controlled (project about a week old). Other than that, my use case should be pretty run of the mill.
Here’s what’s happening:
$ git push origin master
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git@github.com:{username}/{projectname}.git'
Github’s instructions:
Global setup:
Download and install Git
git config --global user.name "Your Name"
git config --global user.email {username}@gmail.com
Next steps:
mkdir projectname
cd projectname
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:{username}/{projectname}.git
git push origin master
Ikke
97.8k23 gold badges96 silver badges120 bronze badges
asked May 5, 2009 at 23:13
7
I was having the same issue and then smacked myself in the head because I hadn’t actually added my project files.
git add -A
git commit -am "message"
git push origin master
Till
22.1k4 gold badges58 silver badges88 bronze badges
answered Nov 14, 2009 at 2:17
Joey GreenJoey Green
3,0403 gold badges18 silver badges14 bronze badges
2
The error message leads to the conclusion that you do not have a master branch in your local repository. Either push your main development branch (git push origin my-local-master:master which will rename it to master on github) or make a commit first. You can not push a completely empty repository.
answered May 6, 2009 at 6:32
BombeBombe
80.2k20 gold badges121 silver badges126 bronze badges
3
I had the same issue. I deleted the .git folder then followed the following commands
$ git init$ git add .$ git remote add origin git@gitorious.org:project/project.git$ git commit -m "Initial version"$ git push origin master
![]()
Dan McClain
11.7k9 gold badges47 silver badges67 bronze badges
answered Jun 29, 2011 at 9:55
I have same issue . it’s solved my problem .
İf you init your git . you have to do on Terminal
1) git add .
2)git commit -m "first commit"
For send to bitbucket
3) git push -u origin --all # pushes up the repo and its refs for the first time
answered Nov 22, 2013 at 12:01
![]()
Erhan DemirciErhan Demirci
4,1214 gold badges35 silver badges43 bronze badges
0
I just had the same problem while creating my first Git repository ever. I had a typo in the Git origin remote creation — turns out I didn’t capitalize the name of my repository.
git remote add origin git@github.com:Odd-engine
First I removed the old remote using
git remote rm origin
Then I recreated the origin, making sure the name of my origin was typed EXACTLY the same way my origin was spelled.
git remote add origin git@github.com:Odd-Engine
No more error! 🙂
answered Apr 9, 2012 at 22:21
I had the same error, as Bombe said I had no local branch named master in my config, although git branch did list a branch named master…
To fix it just add this to your .git/config
[branch "master"]
remote = origin
merge = refs/heads/master
Kinda hacky but does the job
answered Aug 13, 2009 at 12:59
make sure you are on a branch, at least in master branch
type:
git branch
you should see:
ubuntu-user:~/git/turmeric-releng$ git branch
* (no branch)
master
then type:
git checkout master
then all your changes will fit in master branch (or the branch u choose)
answered Sep 9, 2011 at 18:22
error: failed to push some refs to 'git@github.com:{username}/{projectname}.git'
Unless you’re generalizing the error message, it looks like you literally put git@github.com:{username}/{projectname}.git as your remote Git repo. You should fill in {username} with your GitHub username, and {projectname} with your project’s name.
answered Sep 15, 2009 at 22:01
mipadimipadi
391k88 gold badges518 silver badges477 bronze badges
To actually resolve the issue I used the following command to stage all my files to the commit.
$ git add .
$ git commit -m 'Your message here'
$ git push origin master
The problem I had was that the -u command in git add didn’t actually add the new files and the git add -A command wasn’t supported on my installation of git. Thus as mentioned in this thread the commit I was trying to stage was empty.
answered Jan 29, 2011 at 21:45
AsciantAsciant
2,1301 gold badge15 silver badges25 bronze badges
1
It looks like this question has a number of answers already, but I’ll weigh in with mine since I haven’t seen any that address the issue I had.
I had this error as well on a brand new github repository. It turns out the user I was pushing from did not have push access. For some reason, this results in an «ERROR: repository not found» error instead of some sort of access error.
Anyway, I hope this helps the poor soul who runs into the same issue.
answered Apr 23, 2012 at 22:20
TomTom
18.3k15 gold badges71 silver badges80 bronze badges
i fixed my problem….
not sure what the problem was but using the gitx interface to commit my staged files, then…
$ git push origin master
worked…
i am having the same problem…
created a new folder added in the bort template files…
$ git commit -m 'first commit'
$ git remote add origin git@github.com:eltonstewart/band-of-strangers.git
$ git push origin master
then i get the same error…
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to ‘git@github.com:eltonstewart/band-of-strangers.git’
![]()
Arnis Lapsa
44.7k28 gold badges114 silver badges192 bronze badges
answered May 16, 2009 at 5:49
cd app
git init
git status
touch test
git add .
git commit -a -m"message to log "
git commit -a -m "message to log"
git remote add origin
git remote add origin git@git.google.net:cherry
git push origin master:refs/heads/master
git clone git@git.google.net:cherry test1
Cody Gray♦
236k50 gold badges486 silver badges566 bronze badges
answered Apr 25, 2011 at 6:34
I had same issue. I had mistakenly created directory in machine in lower case. Once changed the case , the problem solved(but wasted my 1.5 hrs 🙁 )
Check it out your directory name and remote repo name is same.
answered Feb 4, 2012 at 17:59
had the same issue a minute ago and then fixed it
create a repository in github called wordpress…
cd wordpress
git init
git add -A
git commit -am “WordPress 3.1.3″ or any message
git remote add origin git@github.com:{username}/wordpress.git
git push -u origin master
this should work to resolve the refspec issue
Riduidel
21.9k13 gold badges84 silver badges183 bronze badges
answered May 26, 2011 at 20:07
David ChaseDavid Chase
2,0451 gold badge18 silver badges24 bronze badges
2
This can also happen because github has recently renamed the default branch from «master» to «main» ( https://github.com/github/renaming ), so if you just created a new repository on github use git push origin main instead of git push origin master
answered Dec 18, 2020 at 1:05
mechatronermechatroner
1,2321 gold badge17 silver badges25 bronze badges
I mistankly put a space after the — so instead of -m I had — m
Just something to look for.
answered Mar 6, 2010 at 23:20
I think in older version of git, you should commit at least one file first, and then you can «push origin master» once again.
answered Mar 7, 2010 at 10:33
great.. its the issue with empty directory only nothing else. I got my issue resolved by creating one binary file in each directory and then added them.
answered Mar 13, 2010 at 21:20
Initital add & commit worked like a charm. I guess it’s just a matter of understanding Git’s methodology of managing a project within the repository.
After that I’ve managed to push my data straight-away with no hassle.
answered Mar 28, 2011 at 16:28
![]()
Matthew MorekMatthew Morek
2,8262 gold badges17 silver badges13 bronze badges
I just encountered this problem, and it seemed to be caused by my not adding a custom commit message above the default commit message (I figured, why write «initial commit», when it clearly says that very same thing in the Git-generated text below it).
The problem resolved when I removed the .git directory, re-initialized the project directory for Git, re-added the GitHub remote, added all files to the new stage, committed with a personal message above the auto-generated message, and pushed to origin/master.
answered Jun 13, 2014 at 23:46
25406252540625
10.7k8 gold badges49 silver badges55 bronze badges
When you create a repository on Github, It adds a README.md file to the repo and since this file might not be there in your local directory, or perhaps it might have different content git push would fail.
To solve the problem I did:
git pull origin master
git push origin master
This time it worked since I had the README.md file.
answered Sep 6, 2014 at 22:30
![]()
Sahil SinghSahil Singh
3,17142 silver badges58 bronze badges
Before the first commit, try add some file like readme.txt. This will «force» the remote repo create the branch master in case that not exists. It’s worked to me.
answered Oct 10, 2014 at 16:35
This is very old question but for all new people who will end up here like me.
This solution is only for
error: src refspec master does not match any.
error for new repo created
You need to add your
git config user.email "your email"
git config user.name "name"
Only after adding email and name add files to git and commit
git add .
git commit -m "message"
It will work like charm
answered Feb 16, 2015 at 13:03
![]()
PankajPankaj
1,2321 gold badge9 silver badges21 bronze badges
I have this error too, i put a commit for not push empty project like a lot of people do but doesn’t work
The problem was the ssl, y put the next
git config —system http.sslverify false
And after that everything works fine 🙂
git push origin master
answered Feb 16, 2016 at 4:48
I was having same problem/error.I was doing git push -u origin master instead i just did git push origin master and it worked.
answered Sep 12, 2016 at 10:54
![]()
Ali AkramAli Akram
1894 silver badges12 bronze badges
go to control panel -> manage your credentials and delete github credentials if any.
answered Sep 15, 2019 at 17:38
![]()
Bumping an old thread.
If you have created a repository on Github with a Readme or a .gitignore, you might have to rebase the local master with the remote master. Because, if you are using a project scaffolding tool, like create-app, it creates these files for you, and the remote master needs to be synced with your local before you push.
If you are creating an empty repository on Github, then you can simply push.
answered Jul 7, 2020 at 20:29
![]()
Rutwick GangurdeRutwick Gangurde
4,6549 gold badges49 silver badges85 bronze badges
As some commented above, the problem could be that you do not have email and username or also in my case the problem was that I was trying to push the branch with a different email in the configuration, to check this:
git config --list
to modify it (globally):
git config --global user.email "email@email.com"
answered Apr 24, 2022 at 20:06
AlezDsGsAlezDsGs
111 silver badge3 bronze badges
I had the same problem, some of the users have answered this. Before push you must have your first commit.
Now for new users I’ve created a series of simple steps. Before that you need to install git and run in command line:
- git config user.email «your email»
- git config user.name «name»
The steps for creating a remote repository (I use dropbox as remote repository):
1. create a directory in Dropbox (or on your remote server)
2. go to the Dropbox dir (remote server dir)
3. type git command: git init --bare
4. on your local drive create your local directory
5. go to local directory
6. type git command: git init
7. add initial files, by typing git command:: git add <filename>
8. type git command: git commit -a -m "initial version" (if you don't commit you can't do the initial push
9. type git command: git remote add name <path to Dropbox/remote server>
10. git push name brach (for first commit the branch should be master)
answered Feb 24, 2015 at 8:53
(Note: starting Oct. 2020, any new repository is created with the default branch main, not master. And you can rename existing repository default branch from master to main.
The rest of this 2014 answer has been updated to use «main«)
(The following assumes github.com itself is not down, as eri0o points out in the comments: see www.githubstatus.com to be sure)
If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:
git pull --rebase
git push
The full syntax is:
git pull --rebase origin main
git push origin main
With Git 2.6+ (Sept. 2015), after having done (once)
git config --global pull.rebase true
git config --global rebase.autoStash true
A simple git pull would be enough.
(Note: with Git 2.27 Q2 2020, a merge.autostash is also available for your regular pull, without rebase)
That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/main (or origin/yourBranch: git pull origin yourBranch).
See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.
I would recommend a:
# add and commit first
#
git push -u origin main
# Or git 2.37 Q2 2022+
git config --global push.autoSetupRemote true
git push
That would establish a tracking relationship between your local main branch and its upstream branch.
After that, any future push for that branch can be done with a simple:
git push
Again, with Git 2.37+ and its global option push.autoSetupRemote, a simple git push even for the first one would do the same (I.e: establishing a tracking relationship between your local main branch and its upstream branch origin/main).
See «Why do I need to explicitly push a new branch?».
Since the OP already reset and redone its commit on top of origin/main:
git reset --mixed origin/main
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin main
There is no need to pull --rebase.
Note: git reset --mixed origin/main can also be written git reset origin/main, since the --mixed option is the default one when using git reset.
|
fatal: No such remote ‘origin’ |
|
fatal: No such remote ‘origin’
fatal: No such remote ‘origin’
Скорее всего Вы пытаетесь выполнить
$ git remote set-url origin https://github.com/name/project.git
Попробуйте сперва выполнить
$ git remote add origin https://github.com/name/project.git
2
To https://github.com/YourName/yourproject.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘https://github.com/YourName/yourproject.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push —help’ for details.
Скорее всего Вы пытаетесь выполнить
git push origin master
в новом репозитории.
При этом, когда
Вы создавали удалённый репозиторий на github Вы отметили опцию initialize with readme file.
Таким образом на удалённом репозитории файл
README.md
есть, а на локальном нет. Git не
понимает как такое могло произойти и предполагает, что на удалённый репозиторий кто-то (возможно Вы)
добавил что-то неотслеженное локальным репозиторием.
Первым делом попробуйте
$ git pull origin master
$ git push origin master
Git скачает файл
README.md
с удалённого репозитория и затем можно будет спокойно пушить
Если сделать pull не получилось, например, возникла ошибка
From https://github.com/andreiolegovichru/heiheiru
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
Попробуйте
$ git pull —allow-unrelated-histories origin master
$ git push origin master
ERROR: Permission to AndreiOlegovich/qa-demo-project.git denied to andreiolegovichru.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Возможная причина — git не видит ваш ключ. Либо ваш ключ уже используется для другого удалённого
хранилища.
Решить можно удалив стандарный ключ id_rsa.pub создать новую пару и добавить на удалённое хранилище.
Если этот способ не подходит — нужно настроить config.