iOS如何上傳代碼到Github
很多iOS開發(fā)者想開源自己的代碼或者demo,開源到Github是個不錯的選擇,那么如何上傳我們的代碼到Github,令所有人可以下載使用呢?這里我們的目的很明確,就是上傳我們本地電腦里面的一份代碼到Github,所以我們不講git的初級和高級用法。
第一步、申請Github賬號。https://github.com/,如果已經(jīng)有Github賬號,那么直接進入第二步。
第二步、配置Github的ssh key。
1.設(shè)置git的user name和email:
git config –global user.name “zhengwenming”(注意?:global后面是兩個 -哦,不是一個-哦)
git config –global user.email “740747055@qq.com”
2.查看是否已經(jīng)有了ssh密鑰:cd ~/.ssh
如果沒有密鑰則不會有此文件夾,有則備份刪除
3.保存密鑰:
ssh-keygen -t rsa -C “XXXXXX@qq.com”
按3個回車,密碼為空。
Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
………………
最后得到了兩個文件:id_rsa和id_rsa.pub
4.添加密鑰到ssh:ssh-add 文件名
需要之前輸入密碼。
5.在github上添加ssh密鑰,這要添加的是“id_rsa.pub”里面的公鑰。
打開https://github.com/,登陸,然后添加ssh(到Account setting,賬戶設(shè)置里面有添加ssh key的入口)。
6.測試:ssh git@github.com
The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.
第三步、登錄Github,創(chuàng)建倉庫。
點擊主頁右下方的“+ New repositories”。意思是在Github上面建立一個倉庫。然后要填寫倉庫的信息了,repository name是倉庫的名字,這個用英文,最好這個名字能反映這個項目的作用(這個可以以后修改的);Description填寫倉庫里面項目的簡單扼要描述; 點擊initialize this repositories with README。然后就是直接點擊Creat repositories,創(chuàng)建倉庫。
第四步、開始git命令上傳代碼。(或者用sourcetree更簡單,把github的SSH克隆,然后在本地新建一個工程保存在sourcetree跟蹤那里,寫代碼,然后選中提交推送即可)
1.cd到目標(biāo)文件夾。
2.git init。(在本機上想要創(chuàng)建一個新的git倉庫)
3.git add -A (git add -A: [path]表示把中所有tracked文件中被修改過或已刪除文件和所有untracted的文件信息添加到索引庫,省略表示.,即當(dāng)前目錄。
)
4.git remote add origin xxxxxxxxx xxxxxx就是你倉庫的地址,具體的地址可以去Github上copy。關(guān)聯(lián)遠程倉庫。
5.git commit -m “提交信息”
6.git pull –rebase origin master 更新遠程更新到本地:
推送本地更新到遠程:(注意rebase前面是兩個-,不是一個-,而是 –杠杠,哈哈,別搞錯了)。
7.git push origin master(git push -u origin master) 將本地repo于遠程的origin的repo合并,第一次用-u,系統(tǒng)要求輸入賬號密碼
8.git pull (上傳add的代碼)
9.去Github上面檢查代碼,已經(jīng)上傳成功。
May there be enough clouds in your life to make a beautiful sunset...