AS 之 【使用Git命令将本地项目上传到GitLab仓库】

每一次的积累都是我的财富,例如与这篇有关的文章查找资料不下60篇,所以请珍惜你每次报错而又解决不了的瞬间,记录下来,因为以后肯定还会有人再次犯错。


一.先在gitlab创建一个仓库。

AS 之 【使用Git命令将本地项目上传到GitLab仓库】

二.将本地仓库连接到某个GitLab远程服务器并上传。

  • 初始化本地库
  • 代码添加本地仓库
  • 本地库与远程库关联
  • push到远程仓库

git init .   项目根目录下如没有 .git 仓库 请初始化。
git add . 添加到暂存区
git commit -m'从暂存区提交到仓库'
git remote add origin https:...................... 关联本地库和GitLab库
git push origin master (分支名)将本地内容push至远程仓库中

三.总结异常Git命令。

  1. 异常:Push to origin/master was rejected       
     
    释义:推送到源站/主服务器被拒绝

    解决:

    1.切换到自己项目所在的目录,右键选择Git Bash Here,
    2.在terminl窗口中依次输入命令:
    git pull
    git pull origin master
    git pull origin master --allow-unrelated-histories
    git push origin master

  2. 异常:There is no tracking information for the current branch.
    Please specify which branch you want to merge with.


    释义:当前分支没有跟踪信息,请指定要与哪个分支合并。

    9cbcd0a..0bde444  master     -> origin/master
    当前分支没有跟踪信息。
    请指定您要合并哪一个分支。
    详见 git-pull(1)。 git pull <remote> <branch>


    解决:
    如果您想要为此分支创建跟踪信息,按照提示重新为git pull添加跟踪分支即可:
    git branch –set-upstream-to=origin/master master

  3. 异常:Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.

    释义:请输入一条提交消息来解释为什么需要进行此合并,特别是如果它将更新的上游合并到主题分支中。##以“”开头的行将被忽略,空消息将中止提交。
    AS 之 【使用Git命令将本地项目上传到GitLab仓库】

    解决:
    1.按键盘字母 i 进入insert模式
    2.修改最上面那行黄色合并信息,可以不修改
    3.按键盘左上角"Esc"
    4.输入":wq",注意是冒号+wq,按回车键即可,或输入:q 并按回车键也可退出VIM。