git使用的一些坑和新得(一)

这是一个坑

你要知道作为一个新手对git的使用还处于摸索状态

今天就将这样的坑分享给大家

昨天,接到任务将代码发到远程仓库里。于是,我就天真的按步骤提交了!

然后就:

To https:
! [rejected] z -> z (non-fast-forward)

error: failed to push some refs to ‘https:

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 pull –rebase origin master

放心你要是第一次提交是不可能解决问题的!!!!!

怎么办??

这个时候,你要指定仓库才能成功:

要这样:git pull origin(仓库地址) 分支

这样同步后,你才能愉快的 git push

总结:

git pull origin(仓库地址) master/分支

git add

git commit

git push

最后想说,如何你从远程仓库创建了一个有带readme的文件记得先pull , 再提交代码。

使用git还有些不明白的地方,本地的仓库与远程仓库应该是一一对应的吧!一个本地仓库可以对应多个仓库地址。

还有一点:当你需要删除远程仓库里的多余的代码。我还是没有怎么搞明白。利用git rm 文件名,倒是将本地的删除了,就是不知道远程仓库里怎么删除,有点不明白。难道要再次提交。老火啊!

路漫漫其修远兮,吾将上下求索!!!!!

最后鸣谢:廖雪峰的官方网站https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

原文地址:https://www.cnblogs.com/phying/p/8857718.html