以前一直用的SVN,今天開始轉變成Git,并開始上傳第一個demo到github倉庫。
首先來說說svn和git的區別,
svn是集中式版本管理控制系統,git是分布式版本管理控制系統,這是兩者最大的區別。其他區別就不贅述了。
git作為支持分布式版本管理的工具,它管理的庫(repository)分為本地庫、遠程庫。
其中有兩個命令,可能有的讀者不是很明白,git commit操作的是本地庫,git push操作的是遠程庫。git commit是將本地修改過的文件提交到本地庫中,git push是將本地庫中的最新信息發送給遠程庫。----一開始我也有點暈了,我也是新手。哈哈哈哈
下面來談談,怎么上傳代碼到github
一 首先注冊github賬號,記住用戶名和密碼,然后建立一個repository,例如 test,這個倉庫的地址https://github.com/xxx/test.git 這是http/https地址,另外還有一個 SSH地址, 這個相信不用說了吧。
二 點 Settings-Personal settings-SSH keys-Add SSH keys,這個SSH key自己生成。
step1 ,檢查存不存在key ,終端命令 ls -al ~/.ssh,如果不存在
step2,生成一個新的SSH keys,
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter file in which to save the key (/Users/you/.ssh/id_rsa):[Press enter]
Enter passphrase (empty for no passphrase):[Type a passphrase]Enter same passphrase again:[Type passphrase again]
Your identification has been saved in /Users/you/.ssh/id_rsa.Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
在 /users/you/.ssh/id.rsa.pub 中復制ssh key,填寫在剛才Add SSH Keys,那地方。
三,就是檢驗下,看看能不能連接上,ssh -T 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,
The authenticity of host 'github.com (207.97.227.239)' can't be established.RSA key fingerprint is nss2VhNB0Y62VIToM+/qYe3HS4TPXmrhuBxjUz4l/I8=.Are you sure you want to continue connecting (yes/no)? 點yes,繼續
出現 Hiusername! You've successfully authenticated, but GitHub does notprovide shell access.
就已經完成了。
恭喜,你已經成功設置了 你的 SSH Keys。
四,cd 到你的本地工程目錄 cd? ~/desktop/xxx
在工程目錄下,建立一個本地倉庫,git init //這是初始化在這個文件夾中建立一個空庫
git add? //這個命令 你可以直接? git add . 這是把當前文件夾中的所有文件都加入到上傳的列表中(注意要有空格),你還可以添加具體的文件 git add 你要添加的文件
git commit -m “說明文字” //提交文件到本地庫
五,接下來就是提交代碼到遠程倉庫了,也就是我們在github上面創建的 倉庫。
git remote add origin https://github.com/xxx/test.git, test就是你剛才在github web頁面上建立的repository,origin就是一個別名,用git remote 查看,下面有 origin,就對了。也可用git remote -v查看、
執行命令 git push -u origin master? 提交代碼到遠程倉庫,你就等著提交吧,然后去github 網站查看你提交的項目。
完。。。