git 修改远程仓库源

自己已经写好了一个项目,想上传到 github

github 创建新项目

新建 README.md , LICENSE

本地项目添加 github 远程仓库源

  • 不是git项目
        git remote add origin https://USERNAME:PASSWORD@github.com/USERNAME/pro.git
    
  • 已是git项目,先删除再添加
        git remote rm origin
        git remote add origin https://USERNAME:PASSWORD@github.com/USERNAME/pro.git
    
    

冲突

  1. 如果本地已有了git项目,相当于有两个项目,这时候直接 pull 或者 push 在新版本会报错:

Git refusing to merge unrelated histories

需要加上 --allow-unrelated-histories.因为新版本默认关闭了这个选项
2. 我的github项目新建的时候写了 README 文件,而我本地项目也有 README.md。这个时候运行 git pull 会提示 confilct.
关于git的 merge 操作我一直比较懵,所以我用git rm ,等成功 git push 后 再chekcout:
git rm README.md git push git checkout -- README.md

从已有的git项目导入到 github

导入个人git项目到 github 的正确姿势
code import
git[ssh]😕/git:pass@example.com/var/git/pro.git

添加 branch 的方式导入到github

git remote add branch https://USERNAME:PASSWORD@github.com/USERNAME/pro.git
git pull branch
posted @ 2017-12-25 16:49  真理君的宿敌  阅读(9979)  评论(0编辑  收藏  举报