对Git不了解的同学可以先去这个网站Git学习 ,对Git进行一个初步的了解学习
Git工具的选择
傻瓜教程嘛,讲道理的话肯定不会教大家通过命令行去使用Git的,今天就在这里教大家如何借助如sourceTree或Tower这样的工具去玩转Git(当然工具不只这个两个其它的不做推荐了)
一 建立仓库
用Git进行代码版本管理,肯定得先有个仓库啊,仓库的选择一般按公司的要求来,现在免费得代码托管网站也有很多,目前我在用的有两个gitlab(公司内部使用,只能内网访问),还有一个就是在家里面用的Git@OSC,当然国内还有一个CODING也非常不错(CODING的IOS项目开源了写的很不错有兴趣的同学可以去他们网站上找一下),选择好你要用的代码托管网站进行注册,下面我就用Git@OSC进行个示范
1.新建仓库



2.将你建立的仓库clone到本地
打开已经下载,注册好的sourceTree



二 提交代码
1.我们已经把托管代码网站上的仓库clone到了本地,但是现在仓库里面没有项目,现在新建一个项目(或者用已有的项目)

2.点开我们新建项目文件夹,全选复制里面的文件

3.然后打开我们刚才新建的仓库的文件夹,把我们拷贝的内容粘贴进去

4.然后用sourceTree打开我们GitDemo这个仓库

Git代码管理的所有操作的第一步永远都是,将代码提交到本地,但是有些东西是不用提交的,所以在把代码提交到本地仓库之前我们需要通过
gitignore来设置,方法就是点击上图中得设置,选择 高级

点击编辑 然后把我下面贴得内容拷贝进去(经过检验的gitignore),关于gitignore这里不做过多讲解,有兴趣可以自行搜索
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.Ripa
*.xcuserstate
contents.xcworkspacedata
project.xcworkspace
UserInterfaceState.xcuserstate
project.xcworkspace/
xcuserdata/
UserInterface.xcuserstate
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
.DS_Store
Pods
Pods/*

然后点击上图中得为暂存文件

到这一步我们已经把代码提交到了本地仓库里

我们现在没有建其他的分支,所以之后一个master分支,也就是主分支,点击推送就把可以把代码成功推送到OSChina的远程仓库了

三 Git分支
我上面讲的只是sourceTree的基本用法,下面我简单的跟大家讲一下分支的使用,对于Git分支学习请大家移步Git Flow

下面我们就以develop分支为例(常用分支,一般开发都在这个分支上开发,由一个固定的人维护master分支),点击上图的分支选项


现在这个develop分支只是在我们的本地,无法多人开发时共同在这个分支上进行开发,我们需要把它推送到远端, 点击推送即可

这个时候你的远端也有了develop分支,如果你不想要这个 分支了 ,想把这个分支删除,你应该先确保代码都已经提交到了本地仓库,然后双击你的master分支切换到master分支上面去,最好点击sourceTree的分支选项

然后结合着那个分支图,点击Git Flow选项就可以自己尽情的试验分支的使用了 , 至于代码冲突,我的建议是提高更新频率,有删除,新加的操作最好立即更新,当冲突出现了,也是可以用sourceTree辅助解决的,这次没办法演示就先到了这里了,Git傻瓜教程完结 have Fine
各位
网友评论