美文网首页
提交代码到github第二弹

提交代码到github第二弹

作者: 向着远方奔跑 | 来源:发表于2016-11-18 17:57 被阅读0次
    • 建立git仓库
      cd到本地项目根目录下,执行git命令:
      git init
      此时是在本地创建git版本库
    • 将项目的所有文件添加到仓库中
      git add .
      此时是把添加的文件修改放在本地版本库的暂存区(stage)中
      如果想添加某个特定的文件,只需把 . 换成特定的文件名即可
    • 提交文件到本地版本库
      git commit -m "自己命名"
      此时才把添加的文件真正添加到版本库中,即把暂存区的所有内容提交到当前分支master
      git添加文件原理图
    • 去github上创建自己的Repository,复制仓库的https地址
    • 将本地的仓库关联到github上
      git remote add origin https://github.com/Madridliu/MyWeather
      后面的https链接地址换成你自己的仓库url地址
    • 上传代码到github远程仓库
      git push -u origin master
      第一次加-u,以后不用加

    问题总结

    • 若出现Couldn't resolve host 'github.com'问题,见下图

      图中不用pull到本地,即不用git pull origin master
      但是若在github建立仓库后第一次提交需要先pull一下,即使个github和本地版本库同步起来
      直接输入git config --global --unset https.proxy然后再push
    • 若出现
      $ git push -u origin master To https://github.com/Madridliu/WeatherTestDemo ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/Madridliu/WeatherTestDemo' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
      是因为github远程库中文件进行了修改,与本地库不一致导致的
      可以先把远程库中的文件pull到本地,使本地和远程库一致
      输入git pull --rebase origin master
      然后再push,见下图

    相关文章

      网友评论

          本文标题:提交代码到github第二弹

          本文链接:https://www.haomeiwen.com/subject/wvkspttx.html