2012年12月7日 星期五

Git & GitHub 初體驗


Git

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

本身只是初學者而已,絕無唬爛,只聽說 Git 很潮,最主要對我工作有幫助。原本管理文件方式是複製一份,修改,用 timestamp 改名,但這種方式實在是太蠢了,很難分辨哪些有改哪些沒改,總是有一次忘記用 timestamp 改名。Git 可以說是我的救星 ((雖然我還在研究中)),Documentation 是好起點。

((Git 當然可以管理文件))

((使用前先設定好:https://help.github.com/articles/set-up-git,username & email))



GitHub

GitHub is a web-based hosting service for software development projects that use the Git revision control system.

這不是免費的午餐,但想吃免錢的,得把全部 repo 公開出來。




如何把 GitHub 當成 remote repo?當然要註冊一個 GitHub 帳號,聽完說明會 ((GitHub Bootcamp)),試著生 repo ((HelloWorld)),這是基本的:
https://github.com/Meng-Gen/HelloWorld
這就是我第一個 GitHub repo ((羞))


如何把 HelloWorld clone 下來?
git clone git@github.com:Meng-Gen/HelloWorld.git
然後就吐一堆機機歪歪的 error message,好的方式是走 HTTPS,但這邊用 SSH,是打算用 GitHub 當 remote disk repo。

沒關係,我們先造 SSH Keys ((https://help.github.com/articles/generating-ssh-keys))
ssh-keygen -t rsa -C "your_email@youremail.com"

密碼記得弄複雜一點。ssh-keygen 會產生兩個檔案:id_rsa & id_rsa.pub,為了跟 GitHub 溝通,我們要把 id_rsa.pub,也就是 RSA public key 告訴他。

Account settings => SSH Keys => Add SSH key => Title 不用理他,用文字編輯器把 id_rsa.pub 打開,全選,複製,貼到 Key => Add Key ((綠色按鈕))

把 RSA private key 加到 SSH:
ssh-agent bash --login -i
ssh-add <private_key_filepath>

Check:
ssh-add -l
要有東西。

搞定之後,終於可以快快樂樂用 git clone ((請留在 Git bash prompt))
$ git clone git@github.com:Meng-Gen/HelloWorld.git
Cloning into 'HelloWorld'...
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is <fingerprint>.
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.
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
Receiving objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)



舒服,有東西惹。接著就來研究怎麼 push/pull 吧!
$ git add file2.txt
$ git commit -m"Hello"
$ git push
成果發表:https://github.com/Meng-Gen/HelloWorld/blob/master/file2.txt



PS.

沒有留言:

張貼留言