美文网首页
实操:本地Git仓推送到Github仓库

实操:本地Git仓推送到Github仓库

作者: AgonyTang | 来源:发表于2018-07-14 12:42 被阅读27次

    实操:本地Git仓推送到Github仓库

    本地git的安装配置网上教程又多有全面,这里直接跳过

    1.关联Git账号和Github账号

    1).创建SSH Key

    ssh-keygen -t rsa -C "user.email"

    执行上述命令,创建SSH Key,email就是本地git配置的中的email(可用git config user.email 查看),执行完成后,进入用户home目录下.ssh 目录,id_rsa.pub 里面的内容就是生成的公钥Key。

    2).将上面的SSH Key添加到github上,如下图:

    Github添加SSH Key.png

    完成上述2步骤之后,执行:

    ssh -T git@github.com

    如果出现 You’ve XXX successfully authenticated, but GitHub does not provide shell access。
    这就表示已成功连上github。

    2. 在github上创建空仓库

    这个就不详细说了,点击下鼠标的事情,这里要注意的是,最好创建“空”仓库,避免不需要的麻烦,就是在github上创建仓库的时候,除了仓库名称和描述自由填写,其余的保持默认,如下图:


    红色框中保持默认.png

    上图红色框中保持默认,主要市为了避免出现因为仓库不是“真空”出现冲突,导致报:

    fatal: remote origin already exists

    或者

    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    当然上述的错误肯定市可以解决的,这里不说了,自行搜索。如果想避免,就按照我上面说的,仓库保持“真空”上阵。

    3.push 本地仓代码到github仓

    在本地代码目录下,依次执行如下命令:

    git init

    初始化代码仓

    git add .

    将项目所有文件添加到仓库中

    git commit -m "xxx"

    本地commit代码

    git remote add origin github仓的SSH链接

    本地仓库关联远程仓库

    git push origin master

    push代码到github。

    打完收工。

    相关文章

      网友评论

          本文标题:实操:本地Git仓推送到Github仓库

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