几乎所有iOS程序员都上过GitHub寻找开源类库,的确,GitHub上有大量优秀的开源类库供大家学习。但是如何在Xcode中上传代码至GitHub呢?

(开始之前先安装git,具体方法这里讲的很清楚:http://git.oschina.net/progit/1-起步.html)

开始

首先我们新建一个工程,记得要勾选Create git repository on:

这说明使用Source Control,会默认在工程中创建git repository。然后工程新建完成后,会在右侧边栏看到这些信息,说明已经启用Source Control

如果没有使用Source Control,则是这样的:

现在我们已经在工程中启用了Source Control,这样就可以使用git来管理工程版本了

但是如果我们想对一个未启用git的工程加入git的功能怎么做呢?我们可以使用命令行来开启此功能,新建一个工程,不勾选Create git repository on,此时我们没有开启Source Control,然后我们手动创建git管理,如下图所示:

YiBantekiiMac-3:UseGit YiBan$ cd /Users/YiBan/Documents/iOS_Dev/ManualGitDemo
YiBantekiiMac-3:ManualGitDemo YiBan$ git init
Initialized empty Git repository in /Users/YiBan/Documents/iOS_Dev/ManualGitDemo/.git/

使用

git init

来初始化一个空的git仓库,现在使用ls-la命令查看目录下的所有文件(包含隐藏文件)

total 16
drwxr-xr-x   7 YiBan  staff   238  5 12 16:10 .
drwxr-xr-x 52 YiBan staff 1768 5 12 16:06 ..
-rw-r--r--@ 1 YiBan staff 6148 5 12 16:10 .DS_Store
drwxr-xr-x 9 YiBan staff 306 5 12 16:06 .git
drwxr-xr-x 12 YiBan staff 408 5 12 16:06 ManualGitDemo
drwxr-xr-x 5 YiBan staff 170 5 12 16:06 ManualGitDemo.xcodeproj
drwxr-xr-x 5 YiBan staff 170 5 12 16:06 ManualGitDemoTests

此时我们看到除了三个文件之外还有两个隐藏文件,.DS_Store和.git,.DS_Store是由OS X生成的文件,包含了文件夹中的位置属性,.git则是启用了Source Control自动生成的目录,然后使用git status查看当前状态:

YiBantekiiMac-3:ManualGitDemo YiBan$ git status
On branch master Initial commit Untracked files:
(use "git add <file>..." to include in what will be committed) .DS_Store
ManualGitDemo.xcodeproj/
ManualGitDemo/
ManualGitDemoTests/ nothing added to commit but untracked files present (use "git add" to track)

说明初始化成功了,显示出了未被追踪的文件。不过我们并不希望把.DS_Store也加入的git中,因为那文件对我们没有任何用处,我们可以忽略它,具体做法是:新建一个文件,命名为.gitignore,然后使用文本编辑器输入以下信息:

# Xcode

.DS_Store

*/build/*

*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap

保存至工程文件夹中,这样我们目录中就多出一个.gitignore文件了,这时我们再用git status命令查看当前状态:

YiBantekiiMac-3:ManualGitDemo YiBan$ git status
On branch master Initial commit Untracked files:
(use "git add <file>..." to include in what will be committed) .gitignore
ManualGitDemo.xcodeproj/
ManualGitDemo/
ManualGitDemoTests/ nothing added to commit but untracked files present (use "git add" to track)

这里看到已经没有.DS_Store了,说明.gitignore已经把.DS_Store忽略了。现在可以提交了,使用

git add .

此命令先将文件添加至暂存区域,但还没有提交,查看下状态:

YiBantekiiMac-3:ManualGitDemo YiBan$ git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: .gitignore
new file: ManualGitDemo.xcodeproj/project.pbxproj
new file: ManualGitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file: ManualGitDemo/AppDelegate.h
new file: ManualGitDemo/AppDelegate.m
new file: ManualGitDemo/Base.lproj/Main.storyboard
new file: ManualGitDemo/Images.xcassets/AppIcon.appiconset/Contents.json
new file: ManualGitDemo/Images.xcassets/LaunchImage.launchimage/Contents.json
new file: ManualGitDemo/ManualGitDemo-Info.plist
new file: ManualGitDemo/ManualGitDemo-Prefix.pch
new file: ManualGitDemo/ViewController.h
new file: ManualGitDemo/ViewController.m
new file: ManualGitDemo/en.lproj/InfoPlist.strings
new file: ManualGitDemo/main.m
new file: ManualGitDemoTests/ManualGitDemoTests-Info.plist
new file: ManualGitDemoTests/ManualGitDemoTests.m
new file: ManualGitDemoTests/en.lproj/InfoPlist.strings

现在进行提交,使用git commit -m "Initail"命令,引号内的内容是提交的注释,随便写什么都可以:

YiBantekiiMac-3:ManualGitDemo YiBan$ git commit -m "Initial"
[master (root-commit) 83bbefc] Initial
17 files changed, 803 insertions(+)
create mode 100644 .gitignore
create mode 100644 ManualGitDemo.xcodeproj/project.pbxproj
create mode 100644 ManualGitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
create mode 100644 ManualGitDemo/AppDelegate.h
create mode 100644 ManualGitDemo/AppDelegate.m
create mode 100644 ManualGitDemo/Base.lproj/Main.storyboard
create mode 100644 ManualGitDemo/Images.xcassets/AppIcon.appiconset/Contents.json
create mode 100644 ManualGitDemo/Images.xcassets/LaunchImage.launchimage/Contents.json
create mode 100644 ManualGitDemo/ManualGitDemo-Info.plist
create mode 100644 ManualGitDemo/ManualGitDemo-Prefix.pch
create mode 100644 ManualGitDemo/ViewController.h
create mode 100644 ManualGitDemo/ViewController.m
create mode 100644 ManualGitDemo/en.lproj/InfoPlist.strings
create mode 100644 ManualGitDemo/main.m
create mode 100644 ManualGitDemoTests/ManualGitDemoTests-Info.plist
create mode 100644 ManualGitDemoTests/ManualGitDemoTests.m
create mode 100644 ManualGitDemoTests/en.lproj/InfoPlist.strings

再查看下状态:

YiBantekiiMac-3:ManualGitDemo YiBan$ git status
On branch master
nothing to commit, working directory clean

好了,当前工作区是干净的,代码都已经提交完毕了。我们可以用Xcode提交代码,也可以用命令来提交,但是用命令行的话可以做的事情更多一些。使用Xcode可以查看提交的历史纪录,Source Control->History:

添加工程至GitHub

首先必须有GitHub的帐号,没有的话去注册一个,并且还要创建SSH,GitHub使用了公私密钥,确保与你的电脑通讯过程是安全的。

SSH创建过程是这样的:

1. 在命令行输入cd ~/.ssh,然后ls,看看此文件夹下有哪些文件,如果有id_rsa.pub或者id_dsa.pub(名字可能会不同),说明你已经有SSH keys了,你可以将它添加到你的账户中

2. 如果没有的话,你讲得到"No such file or directory "这个错误信息,此时你可以通过命令生成出来:

ssh-keygen -t rsa -C "YOUR EMAIL"

在那里填写你的email地址,之后会被要求填写密码,此时的SSH keys就生成好了,有了SSH Keys后将其添加至你的GitHub账户中就可以了,在账户设置中找到SSH keys这一项,然后填写title和key,现在,你的SSH Key就和GitHub账户绑定了

前往个人主页,新建一个repository(网页右上方),会要输入一些信息:

输入Repository name和描述,然后选创建,会看到repository的链接:

把链接赋值下来,前往Xcode中,Source Control->第一项->Configure...,之后选Remotes:

Add Remote中,输入Name(你工程的名字)和Address(之前的链接地址),然后Source Control->Push,选择刚刚新建的链接,Push~

现在刷新下GitHub主页,你的工程已经添加成功了~!

使用Xcode上传代码至GitHub的更多相关文章

  1. Xcode 上传代码到GitHub

    几乎所有iOS程序员都上过GitHub寻找开源类库,的确,GitHub上有大量优秀的开源类库供大家学习.但是如何在Xcode中上传代码至GitHub呢? (开始之前先安装git,具体方法这里讲的很清楚 ...

  2. Xcode上传代码到github

    1.下载GitHub的Mac客户端 2.在Finder->下载,找到双击安装 3.打开Github Desktop软件, 需要进行登录, 登录的用户名密码就是github的用户信息,(如果没有去 ...

  3. windows上传代码到github

    上传代码到github上有很多种方法,在这里我介绍一种比较简单的一种.工具嘛,越简单越好用啊. 1.首先下载github在windows下的客户端 下载地址:https://desktop.githu ...

  4. iOS如何上传代码到Github

    iOS如何上传代码到Github 很多iOS开发者想开源自己的代码或者demo,开源到Github是个不错的选择,那么如何上传我们的代码到Github,令所有人可以下载使用呢?这里我们的目的很明确,就 ...

  5. 使用webstorm上传代码到github

    使用webstorm上传代码到github 字数681 阅读330 评论0 喜欢5 之前使用过webstorm上传代码到github,过了几个月竟然发现自己忘记了,好记性不如烂笔头啊,今天又重新用了一 ...

  6. git上传代码到github

    git上传代码到github [root@bigdata-hadoop- ~]# git init [root@bigdata-hadoop- ~]# git add zeppelin [root@b ...

  7. GIT如何从本地上传代码到github

    转载请标明出处: http://blog.csdn.net/hanhailong726188/article/details/46738929 本文出自:[海龙的博客] 开篇之前说下题外话,之前写过一 ...

  8. 通过Webstorm上传代码到Github、更新代码后同步到github及克隆github代码到本地的方法

    导读: Github做为IT爱好者分享代码的一个知名的平台,广受大家喜欢,那么我们平时该怎么将自己写的代码上传到github上面保存并且提供给其他人参考? 我想方法不外乎如下几个: 1.直接在gith ...

  9. 如何上传代码到github?

    如何上传代码到github? 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下载地址,下载后一路直接安 ...

随机推荐

  1. SEXTANTE中调用任意C++控制台程序的简单例子

    在sextante中单纯利用python或者调用sextante已有算法进行自定义开发,很多情况下速度不咋给力,同样的操作调用QGIS的C++插件比用sextante里的算法要快,有时候快的 还不止一 ...

  2. 利用Unicorn和Idaemu辅助解决Geekpwn SecretCode

    在前面的些文章里,我提到了怎么交叉编译Unicorn-engine,以及在windows上使用Unicorn python bindings进行分析程序.这一次我介绍下如何使用Unicorn-engi ...

  3. 前端--关于javascript基础

    首先javascript不是浏览器的附属品,只能说它大多数的运行环境是在浏览器中的,但又不仅仅局限于浏览器中.它是一门真正的程序设计语言,在这方面它和java.c.c++.c#是等同的,只不过它不直接 ...

  4. JavaScript ----------------- 原型式继承

    思想:借助原型可以基于已有的对象创建新对象,同时还不必因此创建自定义类型.为了达到这个目的,看看下面的实现方式 function object(o){ function F(){ } F.protot ...

  5. Android中Binder的基础知识点

    Android Binder基础知识点 一 传统IPC和Binder机制的比较 传统IPC: 1)收方无法获得对方进程可靠的UID/PID,从而无法鉴别对方身份. 2)接入点开放,无法建立私有通道. ...

  6. webservice和.net remoting浅谈

    服务器端向客户端发送一个进程编号,一个程序域编号,以确定对象的位置.   webservice和.net remoting都是用来通信的框架,它们最大的优点是可以像调用本地对象一样调用远程对象,比如: ...

  7. CSS 设计彻底研究(四)盒子的浮动与定位

    第四章 盒子的浮动与定位 本章的重点和难点是深刻地理解”浮动“和”定位“这两个重要的性质,对于复杂页面的排版至关重要. 4.1 盒子的浮动 在标准流中,一个块级元素在水平方向会自动伸张,直到包含它的元 ...

  8. C++文件

    参考: C++文件读写详解(ofstream,ifstream,fstream):http://blog.csdn.net/kingstar158/article/details/6859379 fs ...

  9. centos源码安装git

    因为Centos上yum安装的话可能版本比较低,使用中会有一些难以预料的问题出现. 从源代码编译安装方法: #Centos执行: yum install curl-devel expat-devel ...

  10. 磁盘管理二-LVM相关内容

    1.基本概念 LVM:logical volume manager 逻辑卷管理器 LVM构成:物理卷PV,卷组VG(PE物理区域,最小存储单元),逻辑卷LV(LE逻辑区域,最小存储单元) 三者如下图所 ...