zoukankan      html  css  js  c++  java
  • 如何用git命令行上传本地代码到github

    注意:安装的前提条件是配置好Git的相关环境或者安装好git.exe,此处不再重点提及

            上传的步骤:

        本文采用git 命令界面进行操作,先执行以下两个命令,配置用户名和email【设置用戶名和e-mail地址。这是非常重要的,因為每次Git提交都会使用该信息。它被永遠的嵌入到了你的提交中

               git config --global user.email "you@example.com"
               git config --global user.name "Your Name"

            然后开始创建项目并提交至远程git仓库,步骤如下:

            1.进入本地的项目目录,右键“Git Bash here”,调出git命令行界面,然后输入

          git init

           

           2.将目录下的所有文件上传,也可以将“.”换成具体的文件名

          git add .

         

           3.将项目提交到本地仓库

          git commit -m "注释语句"  

           

           4. 在github上创建新的repository

          

            5. 点击 “Create repository”跳转到一个连接,如下红色圈获取到本项目的github地址

            

               6. 将本地的代码关联到github上

              git remote add origin 项目的github地址

             

               7. 上传代码到github之前需要先pull  

             git pull origin master 

               8.上传代码到远程git仓库

             git push -u origin master

              

               9.输入自己github的账号,密码,代码会成功上传上去

    到此步,代码已成功上传至远程仓库。

    ---------------------------------------------------------------   以下是可能出现的错误 --------------------------------------------------------------

    如果輸入$ git remote add origin git@github.com:djqiang(github帳號名)/gitdemo(項目名).git 

        提示出錯信息:fatal: remote origin already exists.

        解決辦法如下:

        1、先輸入$ git remote rm origin

        2、再輸入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不會報錯了!   

        3、如果輸入$ git remote rm origin 還是報錯的話,error: Could not remove config section 'remote.origin'. 我們需要修改gitconfig文件的內容

        4、找到你的github的安裝路徑,我的是C:UsersASUSAppDataLocalGitHubPortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8etc

        5、找到一個名為gitconfig的文件,打開它把裡面的[remote "origin"]那一行刪掉就好了!

        如果輸入$ ssh -T git@github.com
        出現錯誤提示:Permission denied (publickey).因為新生成的key不能加入ssh就會導致連接不上github。

        解決辦法如下:

        1、先輸入$ ssh-agent,再輸入$ ssh-add ~/.ssh/id_key,這樣就可以了。

        2、如果還是不行的話,輸入ssh-add ~/.ssh/id_key 命令後出現報錯Could not open a connection to your authentication agent.解決方法是key用Git
            Gui的ssh工具生成,這樣生成的時候key就直接保存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令行來做。

        3、最好檢查一下在你複製id_rsa.pub文件的內容時有沒有產生多餘的空格或空行,有些編輯器會幫你添加這些的。

        如果輸入$ git push origin master

        提示出錯信息:error:failed to push som refs to .......

        解決辦法如下:

        1、先輸入$ git pull origin master //先把遠程伺服器github上面的文件拉下來

        2、再輸入$ git push origin master

        3、如果出現報錯 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal:
              Could not read from remote repository.

        4、則需要重新輸入$ git remote add origingit@github.com:djqiang/gitdemo.git

  • 相关阅读:
    快速排序
    ​直接插入排序(Straight Insertion Sort)
    希尔排序(Shell Sort)
    直接选择排序(Straight Selection Sort)
    安卓倒计时
    Could not resolve com.android.support:multidex:1.0.2
    黄油刀的配置文件
    黄油刀的配置文件
    Unable to start activity ComponentInfo{com.example.administrator.myapplication/com.example.administrator.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XM
    java禁止实例化的工具类
  • 原文地址:https://www.cnblogs.com/eaglezb/p/6602123.html
Copyright © 2011-2022 走看看