美文网首页
MAC上传本地代码到Github

MAC上传本地代码到Github

作者: a浮生若梦a | 来源:发表于2017-03-18 16:13 被阅读0次

    上传github的时候遇到了问题,这里参考文章 http://www.cocoachina.com/ios/20160212/15024.html  稍作修改后写下

    1.首先有自己的github账号,这里注册地址: https://github.com

    2.创建仓库

    //打开终端输入命令:

    defaults write com.apple.finder AppleShowAllFiles YES

    显示Mac文件的命令:defaults write com.apple.finder AppleShowAllFiles YES

    隐藏Mac文件的命令:defaults write com.apple.finder AppleShowAllFiles NO

    点击“Finder”===>然后点击电脑左上角的苹果标志===>选择强制退出===>选择Finder重新开启。查看有木有.ssh文件,之前没有配置应该是没有这个文件夹的,有的话建议删除掉重新配置。

    //配置SSH keys

    mkdir .ssh      // 创建一个.ssh 文件夹

    cd .ssh          // 进入刚创建的 .ssh文件夹目录里

    ssh-Keygen -t rsa -C “youEmail”      // 双引号里填写你github的邮箱地址

    输入完之后一直敲回车,中间提示输入密码也不用管,继续敲回车便是,直到出现类似这样。

    ls -la          //输入指令,如果输出类似这样的信息,就说明配置成功

    pbcopy < ~/.ssh/id_rsa.pub          //拷贝.ssh/id_rsa.pub里面的内容

    登陆github 点击右上角头像,弹出列表选择“Settings”,然后选择“SSH and GPG keys”。

    添加 SSH Keys,点击===>New Ssh key===>Title(可以写上自己的邮箱)===>key(粘贴在终端复制的SSH Keys)===>点击Add SSH key添加。

    然后回到终端:

    ssh -T git@github.com

    执行完之后会出现 Are you sure you want to continue connecting (yes/no)?  输入 yes 回车

    //上传本地项目到github上

    首先 cd 到本地项目根目录下面

    git init          //建立仓库

    git add .      //  这个命令会把当前路径下的所有文件添加到待上传的文件列表中。如果想添加某个特定的文件,只需把 . 换成特定的文件名即可

    git commit -m "这里写上提交的注释"

    复制新建仓库的地址,如图所示复制一下地址,也可以复制当前请求网页的地址

    git remote add origin https:后面加上复制的url.git    // 关联远程github仓库

    1.如果提示出错信息: fatal: remote origin already exists.  

    2.或者提示错误:fatal: I don't handle protocol 'https:https'

    -->解决办法终端先输入:git remote rm  origin   然后再输入一次关联远程。

    git push -u origin master      //上传代码到github远程仓库,中间可能会让你输入Username和Password,你只要输入github的账号和密码就可以。

    刷新一下你的Github,就可以看到你上传的文件了。是不是很简单呢^o^

    3.如果出现类似于下面这种错误的:

    error: failed to push some refs to 'git@github.com:xxx.git

    hint: Updates were rejected because the tip of your current branch is behin

    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.

    出现这种错误

    出现错误的主要原因是github中的README.md文件不在本地代码目录中,

    通过如下命令进行代码合并: git pull --rebase origin master     (注:pull=fetch+merge)

    4.如果出现下面问题

    To https://github.com/bolagong/RecordLayoutDemo.git

    ! [rejected]        master -> master (fetch first)

    error: failed to push some refs to 'https://github.com/bolagong/RecordLayoutDemo.git'

    hint: Updates were rejected because the remote contains work that you do

    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.

    如果是上面的错误输入命令push: git push -f origin master  (用 -f 参数push)

    执行上面代码后可以看到本地代码库中多了README.md文件

    5.如果出现下面问题

    fatal: unable to access 'https://github.com/bolagong/AVPlayer.git/': Failed to connect to 127.0.0.1 port 1080: Connection refused

    问题5

    看一下是否添加了代理

    通过:    git config --global http.proxy    查询到当前是否设置了代理

    取消这个设置   git config --global --unset http.proxy

    然后继续你的push操作试试,因该就可以了。

    如果还没有好 那么把远程服务器链接在设置一下   

    把这种格式 https://github.com/用户名/存储库.git

    换成SSH的这种     git@github.com:用户名/存储库.git

    然后执行        git remote set-url origin   git@github.com:用户名/存储库.git

    关联好之后,,然后继续push一下,应该就可以了,相关参考文章:(https://help.github.com/articles/changing-a-remote-s-url/)

    相关文章

      网友评论

          本文标题:MAC上传本地代码到Github

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