美文网首页
iOS开发-使用命令行将本地代码上传到GitHub

iOS开发-使用命令行将本地代码上传到GitHub

作者: 爱上火烧的小毛驴 | 来源:发表于2017-03-06 14:36 被阅读43次

1.首先你要拥有GitHub的账号,注册地址:https://github.com/join?source=header

2.准备好准备上传的项目,放置桌面(其他位置也可),使用Xcode创建项目时候自动生成的文件夹即可。

3.打开终端,运行

cd /Users/aurorac/Desktop/XMLDownload

4.建立本地仓库 (Xcode自带创建,iOS开发可不进行这一步)

git init

5.将项目中的所有文件添加到本地仓库中

git add .

6.将add的文件commit到仓库中

git commit -m "XMLDownload"

7.去github上创建自己的Repository,创建页面如下图所示

QQ20170306-142126@2x.png

点击创建,进入下一页面,拿到下面框中的HTTPS地址,进行下一步

QQ20170306-142203@2x.png

8.将本地的仓库与GitHub远程仓库连接起来

git remote add origin https://github.com/zhangjiahuan8888/XMLDownload.git

9.上传github之前,要先pull一下,执行如下命令:

git pull origin master

10.最后一步,上传代码到github远程仓库

git push -u origin master

执行完后,如果没有异常,等待执行完就上传成功了,中间可能会让你输入Username和Password,你只要输入github的账号和密码就行了

注:
在执行到 git push -u origin master 这一步时候,如果出现了下面的错误,发生错误的原因是在创建仓库的时候勾选了Initialize this repository with a README。
github中的README.md文件不在本地代码目录中,

! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'git@github.com:yangchao0718/cocos2d.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.
可以通过如下命令进行代码合并【注:pull=fetch+merge]

执行上面代码后可以看到本地代码库中多了README.md文件
此时再执行语句 git push -u origin master即可完成代码上传到github

相关文章

网友评论

      本文标题:iOS开发-使用命令行将本地代码上传到GitHub

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