git本地代码提交到远程仓库

2021-08-24  本文已影响0人  钓小鱼的猫

操作步骤

git init   // 初始化版本库

git add .   // 添加文件到版本库(只是添加到缓存区),.代表添加文件夹下所有文件 

git commit -m "first commit" // 把添加的文件提交到版本库,并填写提交备注

这样就完成了代码仓库初始化
接下来要把本地的文件上传到远程

git remote add origin 你的远程库地址  // 把本地库与远程库关联

git push -u origin master    // 第一次推送时

git push origin master  // 第一次推送后,直接使用该命令即可推送修改

在实践过程中遇到问题:
执行:

git push -u origin master

爆出错误:

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/east/airtest_iting.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.

解决方案:执行命令

在终端下输入:git push -u origin master -f
   这句话执行的后果就是在远程仓库中进行的相关修改会被删除,使远程仓库回到你本地仓库未修改之前的那个版本,
   然后上传你基于本地仓库的修改。这如果在企业开发中就会让别的程序员的这些天的开发付之东流,一切回到解放前。
上一篇 下一篇

猜你喜欢

热点阅读