无法推送到远程 Git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/855558/
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
can't push to remote Git repo
提问by Geuis
I just jumped into Git yesterday via Github and am moving away from svn. I created a private repo that I intend to use to keep my personal projects synced between work and home. During the process of creating the remote repo, my local files from work were pushed up. Last night, I was able to pull them down to my laptop at home.
我昨天刚刚通过 Github 跳入 Git 并且正在远离 svn。我创建了一个私人仓库,我打算用它来保持我的个人项目在工作和家庭之间同步。在创建远程仓库的过程中,我的本地工作文件被推送了。昨晚,我能够将它们拉到家里的笔记本电脑上。
Now I added some new files to the repo directory at work. I did "git add filename" where "filename" is my file. Then I did "git commit -m 'my message'" and that seemed to work. I can't push them to the remote though. I tried 'git push personal' but got an error:
现在我在工作的 repo 目录中添加了一些新文件。我做了“git add filename”,其中“filename”是我的文件。然后我做了“git commit -m 'my message'”,这似乎奏效了。不过我不能把它们推到遥控器上。我试过 'git push personal' 但出现错误:
To [email protected]:geuis/personal.git
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to '[email protected]:geuis/personal.git'
Svn is really straight forward when it comes to this stuff. I've been trying to read through docs on how Git works, but most of it seems to assume you already know the basics.
Svn 在这方面非常直接。我一直在尝试通读有关 Git 工作原理的文档,但其中大部分内容似乎都假设您已经了解基础知识。
For my situation, what are the basics I need to know? Remote repo on Github, and 2 separate checkouts at work and home that will be manually synced to the remote.
对于我的情况,我需要了解哪些基础知识?Github 上的远程存储库,以及将手动同步到远程的 2 个单独的工作和家庭结帐。
I'm on a Mac.
我在 Mac 上。
回答by
To be able to push to the remote, generally speaking, you need to be up to date with the remote branch. Try git pull
first, then git push
.
为了能够推送到远程,一般来说,您需要与远程分支保持同步。git pull
先试,后试git push
。
Additionally, github recommends you do git push -u personal master
so that the head is set remotely
此外,github 建议您这样git push -u personal master
做,将头设置为远程