zoukankan      html  css  js  c++  java
  • 使用git将本地项目上传至git仓库


    个人博客 地址:https://www.wenhaofan.com/article/20190508220440

    介绍

    一般来说开发过程中都是先在git创建远程仓库,然后fetch到本地仓库,再进行commit push等操作,但是有时候也需要将本地已经开发的项目上传至一个空的远程仓库中,期间也是遇到不少问题,特此总结一下

    初始化本地仓库

    初始化仓库

    git init

    将文件提交至本地仓库

    git commit -m "注释"

    关联线上仓库

    git remote add origin <线上仓库url>

    线上仓库url 为如下链接

    https://github.com/wenhaofan/xxx.git

    提交代码

        常见错误及解决方案

                    现在已经创建好了本地仓库,并关联上了远程仓库,如果我们直接使用git push -u origin master将本地内容推送至线上那么可能会出现出现以下错误

            git push

    failed to push some refs to 'https://github.com/xxx/xxx.git'
    hint: Updates were rejected because the remote contains work that you dogit
    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.

            以上错误很明显的提示先执行 git pull 再push,需要先执行以下指令将远程仓库中master分支中的文件拉取到本地

    git pull origin master

            如果没有抛异常 那么就可以愉快的再次执行 git push 了,如果抛了异常,那么可以接着往下看

            git pull

     * branch            master     -> FETCH_HEAD
    fatal: refusing to merge unrelated histories

            出现这个问题是因为本地库和远程库没有进行关联远, 然后本地推送到远程库, 远端因为这个本地库跟自己没有关联, 所以告知无法合并,该情况有两种解决方法

            第一种:

           先从远端库拉下来代码,然后将本地代码放入本地库中, 然后再执行push提交上去  

            第二种方法:

           使用以下命令,把两段不相干的 分支进行强行合并

    git pull origin master --allow-unrelated-histories

            然后再进行提交

    git push gitlab master:init

            

  • 相关阅读:
    今天看到的一些好文语句摘录
    laravel5 怎么获取数组形式的数据
    laravel5.4将excel表格中的信息导入到数据库中
    phpmax_execution_time
    laravel 5.4 导出excel表格
    使用php函数ini_set()重新设置某个配置的设置值
    艾伟_转载:VS.NET 2010 新功能 [整理] 狼人:
    艾伟_转载:[一步一步MVC]第五回:让TagBuilder丰富你的HtmlHelper 狼人:
    艾伟_转载:.NET 4.0中数组的新增功能 狼人:
    艾伟_转载:一个简单的 Generic Factory 类 狼人:
  • 原文地址:https://www.cnblogs.com/fanwenhao/p/10841133.html
Copyright © 2011-2022 走看看