git 在新存储库上推送原始主错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/827351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Push origin master error on new repository
提问by sutee
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.
我刚开始在 github 上使用 git。我按照他们的指示,在最后一步遇到了错误。我正在检查当前不受源代码控制的现有目录(大约一周前的项目)。除此之外,我的用例应该是完全正常的。
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 '[email protected]:{username}/{projectname}.git'
Github's instructions:
Github 的说明:
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 [email protected]:{username}/{projectname}.git
git push origin master
采纳答案by Bombe
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.
该错误消息导致您master
在本地存储库中没有分支的结论。要么推送您的主要开发分支(git push origin my-local-master:master
这将master
在 github上将其重命名为)或先进行提交。你不能推送一个完全空的存储库。
回答by Joey Green
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
回答by sugnan prabhu
I had the same issue. I deleted the .git folder then followed the following commands
我遇到过同样的问题。我删除了 .git 文件夹然后按照以下命令
$ git init
$ git add .
$ git remote add origin [email protected]:project/project.git
$ git commit -m "Initial version"
$ git push origin master
$ git init
$ git add .
$ git remote add origin [email protected]:project/project.git
$ git commit -m "Initial version"
$ git push origin master
回答by Erhan Demirci
I have same issue . it's solved my problem . ?f you init your git . you have to do on Terminal
我有同样的问题。它解决了我的问题。? 如果你初始化你的 git 。你必须在终端上做
1) git add .
1) git add .
2)git commit -m "first commit"
2)git commit -m "first commit"
For send to bitbucket
用于发送到 bitbucket
3) git push -u origin --all # pushes up the repo and its refs for the first time
3) git push -u origin --all # pushes up the repo and its refs for the first time
回答by Technohazard
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 存储库时遇到了同样的问题。我在 Git origin 远程创建中有一个错字 - 结果我没有将我的存储库的名称大写。
git remote add origin [email protected]: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 [email protected]:Odd-Engine
No more error! :)
没有更多的错误!:)
回答by Technohazard
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...
我遇到了同样的错误,正如 Bombe 所说,我的配置中没有名为 master 的本地分支,尽管git branch
确实列出了一个名为 master 的分支...
To fix it just add this to your .git/config
要修复它,只需将此添加到您的 .git/config
[branch "master"]
remote = origin
merge = refs/heads/master
Kinda hacky but does the job
有点 hacky 但可以完成工作
回答by jose alvarez muguerza
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
ubuntu-user:~/git/turmeric-releng$ git 分支
* (no branch)
master
then type:
然后输入:
git checkout master
then all your changes will fit in master branch (or the branch u choose)
那么您所有的更改都将适合主分支(或您选择的分支)
回答by Asciant
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.
我遇到的问题是 git add 中的 -u 命令实际上并未添加新文件,并且我的 git 安装不支持 git add -A 命令。因此,正如在这个线程中提到的,我试图暂存的提交是空的。
回答by shrikant
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 [email protected]:cherry
git push origin master:refs/heads/master
git clone [email protected]:cherry test1
回答by David Chase
had the same issue a minute ago and then fixed it
一分钟前有同样的问题,然后修复了它
create a repository in github called wordpress...
在 github 中创建一个名为 wordpress 的存储库...
cd wordpress
git init
git add -A
git commit -am “WordPress 3.1.3″ or any message
git remote add origin [email protected]:{username}/wordpress.git
git push -u origin master
this should work to resolve the refspec issue
这应该可以解决 refspec 问题