push到Git时常见的失败

       之前学用git的时候,不想记命令,总是gui和bash交互的用,但是发现总出现push失败的问题,用gui来fetch的时候,显示下拉成功,但事实上并没有,这时候得在bash上用命令来下拉。全部用命令来操作的步骤如下:

第一步,是将该目录git init进行初始化:

第二步, git add -A ,

第三步,git commit -m “description...”

第四步,在github上新建一个远程库,想要将其与我本地的库相关联,使用:

git remote add origin [email protected]:MisterZZL/LeetCode.git

第五步,push到远程端

git push -u origin master

结果报错如下((如果是之前克隆到本地的文件,没有下拉或者下来失败都要先执行第六步)):
error: failed to push some refs to '[email protected]:你的远程库名.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.

从提示可以看出,是由于两者不同步,因此需要先pull,进行合并然后在进行push, 因此先使用

第六步, git pull --rebase origin master

将远程文件同步下来(不知道什么原因,我用GUI来feth显示成功,事实却没有下拉到本地,只能打开bash用命令来完成pull操作),最 后再执行推送

git push -u origin master

这样就不会push失败了!

猜你喜欢

转载自blog.csdn.net/qq_21437451/article/details/81049149