Git本地仓库与远程仓库关联及遇到的问题解决

Git本地仓库与远程仓库关联

关联工具:Git Bash 下载地址

  1. 创建本地项目
  2. 创建Git的远程仓库(可以通过GitHub、GitLab、Gitee等)
  3. 打开Git Bash,切换目录到本地项目路径下,依次输入下面的命令:
//初始化当前项目
git init  

//查看项目的Git状态
git status 

//添加所有项目文件到暂存区
git add 

//对暂存区的文件提交到仓库并对本次操作进行描述
git commit -m '初始化仓库' 

//添加主机名为 origin 的远程仓库
git remote add origin 远程仓库地址

//将本地 master 分支推送到 origin主机的 master 分支
git push -u origin master
//此步骤可能需要输入用户名和密码

2021.12.11更新

今天在进行本地仓库与远程仓库同步过程中,遇到如下报错:

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/shanbingzhen/demo'
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 origin master --allow-unrelated-histories

执行上面的命令,将本地仓库与远程仓库同步,消除差异,之后再按照提交流程提交就能够解决报错了。

参考链接:https://blog.csdn.net/xieneng2004/article/details/81044371


posted @ 2021-10-17 21:56  bingzhen828  阅读(372)  评论(0编辑  收藏  举报