Xcode 提交工程至GitHub有很多方法,这里只描述Xcode自带的Git的使用
第一步
在创建工程时,Source Control 一定要勾选

第二步
在Xcode -> Preferences -> Accounts 新增GitHub账号

其中账号对应的token生成看这里:GitHub Personal Access Token

第三步
本地生成SSH Key,见SSH Key生成
将id_rsa.pub中的公钥复制到GitHub -> Settings -> SSH and GPG keys -> New SSH key

第四步
回到Xcode -> Preferences -> Accounts,选择GitHub,Clone Using 选择SSH,SSH Key 选择你使用在GitHub的SSH中的公钥,见第二步选择的.pub文件

如果有问题SSH Key下会显示,反之则成功。
第五步
选择版本控制导航器,右键项目选择Create "XXX" remote


注意:这里填写的Repository Name是在GitHub中不存的项目名称,否则会报错,所以不需要提前在GitHub中创建新的repository
{"message":"Repository creation failed.","errors":[{"resource":"Repository","code":"custom","field":"name","message":"name already exists on this account"}],"documentation_url":"https://developer.github.com/v3/repos/#create"}
如果创建成功不会有任何提示,如果创建失败可能会提示"Reference 'refs/heads/master' not found (-9)"或者"remote: Repository not found.",不要慌,这时候去GitHub上查看是否有生成对应的repository,如果没有,就重新提交一次;如果已经有了,则找工具栏Source Control -> Push,直接push就可以了。

是否成功,在GitHub上自己看看就知道啦,目前本人操作的完整流程就这些,没有遇到啥问题,如果有大家可以讨论讨论。
第六步
平时在修改完代码要提交时,找工具栏Source Control -> Commit,即可

以上为个人GitHub提交,还未尝试过该方法在合作开发中是否可行。
网友评论