mkdir runoob-git-test # 创建测试目录
cd runoob-git-test/ # 进入测试目录
echo "# 菜鸟教程 Git 测试" >> README.md # 创建 README.md 文件并写入内容
ls # 查看目录下的文件
README
git init # 初始化
git add README.md # 添加文件
git commit -m "添加 README.md 文件" # 提交并备注信息
[master (root-commit) 0205aab] 添加 README.md 文件
1 file changed, 1 insertion(+)
create mode 100644 README.md
# 提交到 Github
git remote add origin git@github.com:tianqixin/runoob-git-test.git
git push -u origin master
Git 推送远程仓库时,出现如下报错:
To gitee.com:wangjiabin-x/light-mvvm.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitee.com:wangjiabin-x/light-mvvm.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.
解决
因为 README.md 文件不在本地代码目录中,可以通过如下命令进行代码合并,得以解决:
git pull --rebase origin master
#or
git fetch origin master
git merge origin master
然后再执行推送命令:
git push origin master
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 vault@coolxy.cn