Git和Github学习记录

将大象放进冰箱只需要三步,将代码放进github也只需要三步

一、选择内容

在本地修改好代码之后,可以选择添加到仓库的内容

$ git add readme.md

如果需要全部添加,只需将readme.md改为.

二、添加说明

$ git commit -m "readme"

三、推送到仓库

$ git push origin master

远程分支拉取到本地

$ git pull origin master

四、问题解决

今天在提交代码到Github的时候遇到了一些问题,在本地提交git push的时候提示:

To https://git.coding.net/xxxx/xxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.coding.net/xxxx/xxx.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.

提示push失败,在push执行前需要执行pull拉取代码,然后再执行 git push origin master

From https://git.coding.net/xxxx/xxx
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

意思是拒绝合并没有联系的历史,本地和远程不是同一个项目

解决方案(两种二选一)

针对refusing to merge unrelated histories问题

#允许合并不相关的内容
$ git pull --allow-unrelated-histories

#提交内容
$ git push 

针对non-fast-forward问题

#强推,本地代码强行覆盖远程`git`仓库
$ git push -f
posted @ 2021-01-29 19:07  Wazty元  阅读(64)  评论(0编辑  收藏  举报