美文网首页Git
玩转GitHub(六) | 上传自己的项目到GitHub上

玩转GitHub(六) | 上传自己的项目到GitHub上

作者: Ricsy | 来源:发表于2019-05-09 00:58 被阅读55次


目录


1. 本地配置github

  • 配置你的名字和Email地址
    git config --global user.name "<Your Name>"
    git config --global user.email "<you@example.com>"

例如:

git config --global user.name "54yimeng"
git config --global user.email "54zifeng@gmail.com"

提示:

  • 注意更换内容
  • 禁止git自动将LF转化成CRLF
    git config --global core.autocrlf false
  • 生成.ssh
    ssh-keygen -t rsa -C "<Your github username>"

提示:

  • 注意更换为你的github账户名.
  • 配置.ssh
  • 测试ssh
    ssh -T git@github.com
  • 查看本地配置
    git config -l

2. 首次提交项目

  • 我的测试项目test(在桌面上)
  • github新建一个仓库为test
  • 项目中打开Git Bash
  • 初始化项目
    git init
  • 将项目上所有的文件添加到仓库中
    git add *
  • 对这次提交进行注释
    git commit -m "Update"
  • 获得仓库地址
  • 将本地的仓库关联github对应的仓库
    git remote add origin <仓库地址>
    例如:
git remote add origin https://github.com/54yimeng/test.git
  • 先将github仓库代码与本地合并
    git pull origin master --allow-unrelated-histories

提示:

  • 为什么要执行这步?
    因为我在创建仓库时,用描述进行了初始化,所以github的仓库不为空. 两个根本不相干的 git 库,一个是本地库,一个是远端库,然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并.,参阅 git 出现 fatal: refusing to merge unrelated histories 错误.
  • 代码上传到github仓库
    git push -u origin master
  • 查看test仓库
  • 查看配置
    git config -l

3. 以后提交项目

  • 进入项目文件夹打开git bash

git add *
git commit -m "Update"
git pull origin master
git push origin master


参阅:



相关文章

网友评论

    本文标题:玩转GitHub(六) | 上传自己的项目到GitHub上

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