Git push error?

1.I just create and initialized a folder and make it a repository, and add 2 folder which are in it. I commit them together by once. Then I add the remote repository, but when I begin to push it, error come out: here is the code I made and the error below:

git init
git add 2048-personal
git add canvas-time-counter
git commit
git remote add origin git@github.com:CharlesLN/front_end.git
git push -u origin master

Then the error come out:

To git@github.com:CharlesLN/front_end.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:CharlesLN/front_end.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

then I keyed git pull
then the info:

warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3
Unpacking objects: 100% (3/3), done.
From github.com:CharlesLN/front_end
*[new branch] master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

Then I keyed git pull remote:

fatal: 'remote' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Then git status
图片描述

So, I don't know where is wrong and who can tell me the problem?
Thank you!

    I have tried over 3 times and it's still the same wrong! please give me some help, thank you !!!
阅读 5.2k
4 个回答

其实就是远程和本地的版本跨度多了。
对不上号了。

请问我写中文您能看懂吗?
can you understand my Chinese?
那个xiangmu文件夹已经瞎了我的钛合金狗眼。
the folder named xiangmu blind my eyes like dog's made in gold with Ti
不过您写的英文我也看懂了。
i can understand your English

远端的内容有修改,需要先pull下来再进行提交。先git pull origin master这样将改动拉下来,然后commit自己的修改,最后push到origin master上面(如果是对应这个分支的话),个人感觉

根据你运行git pull的结果来看,你的Github仓库先前就有master分支了,而且不符合fast-forward push的条件(意思是,本地的master不是建立在远程master基础上的子提交,而是另起炉灶的一个分支)。

因此,这个问题既牵扯到怎么解决合并冲突,又牵扯到与远端版本库中分支的交互,比较复杂。

正常的解决方法是,把远端内容拉回本地(git fetch),在本地合并git merge origin/master或者变基git rebase origin/master master,然后再git push回去。简单粗暴的办法是,git push --force,这样本地的master会强行覆盖远端的master(不推荐,慎用)。

相比之下,你说的教程里是往一个空库进行push,不存在这一问题。

要是还不行的话,可以运行git log --graph --all --pretty=format:'%h%d %s'git remote show origin,把结果贴上来看看。

你本地有个master分支,远端有个master (但本地分支没有跟踪远端分支)。推送被拒绝,然后你

$ git pull
# 出现
> *[new branch] master -> origin/master

这是一个新分支(之前没下载过),并且没有自动和本地 master 和并(因为你没有跟踪他)。所以建议你先合并一下,如果有冲突则解决冲突,最后再推送看看

git merge master origin/master

只是个建议,不保证成功,因为没遇到过。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进