美文网首页
Mac环境下上传项目到GitHub

Mac环境下上传项目到GitHub

作者: 奶茶007 | 来源:发表于2017-03-07 17:07 被阅读134次

    准备

    defaults write com.apple.finder AppleShowAllFiles -bool true  //  终端 显示隐藏文件(需要重新运行Finder)。
    
    • 2
    mkdir .ssh    //终端新建个 .ssh文件
    
    • 3
    cd .ssh  // 进入到刚才新建的.ssh文件目录下
    
    • 4
    ssh-Keygen -t rsa -C "your_email@example.com"       //后面“ ”里面 随意输入个邮箱就行,回车会提示你输入密码什么的,可以无视一直回车下去。
    
    02B425A0-68FA-4203-81BA-6D1D409532A1.png
    • 5
    ls -la     // 查看是否存在 id_rsa(私钥)  id_rsa.pub(公钥) 这两个东西,如果存在就成功了
    
    • 6
    pbcopy < ~/.ssh/id_rsa.pub     //拷贝 公钥
    
    
    • 7
     登陆github,选择Account Settings-->SSH  Keys 添加ssh
     Title:CustomerButton
     Key:打开你生成的id_rsa.pub文件,将其中内容拷贝至此。(通过文本即可打开)
    
    585D923C-05A1-4DC5-8B9F-58B4B30C7CEE.png F37A7DCC-0285-496A-A447-C098023C9476.png
    • 8
    ssh -T git@github.com 
    

    新添加到github上的秘钥左边的点一开始是灰色的,终端执行这个命令后,刷新网页会看到灰色点变成了绿色。

    645D5E17-1919-41CB-B939-CDA0BA4DE27F.png E0951314-A3A0-409A-A3C8-98A436EADA7F.png

    创建项目

    • 1 ,打开终端,先测试一下你的帐号跟github连上没有:
    ssh -T git@github.com 
    

    如果出现如下提示,表示你连已经连上了.

    02B425A0-68FA-4203-81BA-6D1D409532A1.png
    • 2 ,在git创建个人项目
    38F7F447-5369-4D77-8FC9-9BD76C39A712.png

    上传项目
    按照GitHub提供的步骤来就可以:

    …or create a new repository on the command line
    
    echo "# CustomerButton" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/liuyn007/CustomerButton.git
    //更新提交
    git push -u origin master
    
    …or push an existing repository from the command line
    
    git remote add origin https://github.com/liuyn007/CustomerButton.git
    git push -u origin master
    
    …or import code from another repository
    
    You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
    

    出错问题分析
    如果输入$ 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:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
    
    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
    

    本文参考自:
    http://www.jianshu.com/p/e7501b968256

    相关文章

      网友评论

          本文标题:Mac环境下上传项目到GitHub

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