Linux git入門教程

1. github是一個git項目託管網站

註冊地址:https://github.com/signup/free

2. 安裝git程序,執行下面操作

$ cd ~/.ssh    //檢查計算機ssh密鑰

如果沒有提示:No such file or directory 說明你不是第一次使用git,執行下面的操作,清理原有ssh密鑰

 $ ls
 config id_rsa id_rsa.pub known_hosts
 $ mkdir key_backup
 $ cp id_rsa* key_backup
 $ rm id_rsa*

獲得密鑰:

ssh-keygen -t rsa -C "[email protected]"//填寫email地址,然後一直“回車”ok

打開本地..\.ssh\id_rsa.pub文件。此文件裏面內容爲剛纔生成人密鑰。

4. 登陸github系統。點擊右上角的 Account Settings--->SSH Public keys ---> add another public keys

把你本地生成的密鑰複製到裏面(key文本框中), 點擊 add key 就ok了

5. 接着打開git ,測試連接是否成功

如果提示:Hi defnngj You've successfully authenticated, but GitHub does not provide shell access. 說明你連接成功了

6. 設置用戶信息:

6.1

$ git config --global user.name "defnngj"//給自己起個用戶名
$ git config --globla user.email  "[email protected]"//填寫自己的郵箱

6.2

在github中找到 Account Settings--->Account Admin ,找到一下信息:

Your API token is e97279836f0d415a3954c1193dba522f ---keep it secret! Changing your password will

generate a new token

$ git config --global github.user defnngj      //github 上的用戶名
$ git config --globla github.token e97279836f0d415a3954c1193dba522f

====================創建一個項目========================

1. 回到github首頁,點擊頁面右下角“New Repository”

填寫項目信息:

project name: hello world

description : my first project

點擊“Create Repository” ; 現在完成了一個項目在github上的創建。

2. 我們需要使用git在本地創建一個相同的項目。

$ makdir ~/hello-world    //創建一個項目hello-world
$ cd ~/hello-world    //打開這個項目
$ git init    //初始化
$ touch README
$ git add README   //更新README文件
$ git commit -m 'first commit'//提交更新,並註釋信息“first commit”
$ git remote add origin [email protected]:defnngj/hello-world.git   //連接遠程github項目
$ git push -u origin master   //將本地項目更新到github項目上去

現在查看github上面的hello world 項目,是不是發現已經將本地中的README文件更新上來了。 :) 恭喜!


可能的錯誤

$ git remote addorigin [email protected]:defnngj/hello-world.git

錯誤提示:fatal: remote origin already exists.

解決辦法:

$ git remote rm origin

然後在執行:$ git remote add origin [email protected]:defnngj/hello-world.git 就不會報錯誤了

本文是參考官方幫助進行的:http://help.github.com/win-set-up-git/ 基本與官方步驟相同,我在此屬於翻譯了一下!

關於更過的學習:請登陸: http://progit.org/book/zh/進行學習。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章