将本地项目与远程git仓库连接并提交

847 阅读1分钟

方式1

  1. 创建一个空文件夹,然后git clone 远程仓库地址
  2. 将本地项目复制到该文件夹,然后提交

方式2

  1. 打开本地项目文件夹,右键菜单git bash here,或者在命令行中cd到项目文件夹
  2. git初始化git init
  3. 将项目提交到暂存区git add .
  4. 连接本地仓库和远程仓库 git remote add origin 远程仓库地址
  5. 获取远程仓库的最新代码git pull origin master --allow-unrelated-histories
  6. 将项目提交到本地仓库git commit -m 'commit'
  7. 推送到远程仓库git push -u origin master
题外:
1. --allow-unrelated-histories 第一次合并,没有共同祖先,允许合并未知
2. 连接远程仓库其他分支,在orgin后面加分支名称
3. git push -u 第一次提交后,后面可以直接使用git push
4. 如果连接远程仓库后执行其他操作报错 '乱码https' not support,打开文件夹'.git',编辑'config',远程仓库地址前面有个乱码,删除即可(如果找不到.git文件夹,设置文件夹选项,显示隐藏文件夹)