Linux下Git入門基礎

openkk 12年前發布 | 29K 次閱讀 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 "defnngj@gmail.com"http://填寫email地址,然后一直“回車”ok

打開本地..\.ssh\id_rsa.pub文件。此文件里面內容為剛才生成人密鑰。

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

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

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

$ ssh -T git@github.com

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

6. 設置用戶信息:

6.1

$ git config --global user.name "defnngj"http://給自己起個用戶名
$ git config --globla user.email  "defnngj@gmail.com"http://填寫自己的郵箱

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 git@github.com:defnngj/hello-world.git   //連接遠程github項目
$ git push -u origin master   //將本地項目更新到github項目上去

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


可能的錯誤

$ git remote addorigin git@github.com:defnngj/hello-world.git

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

解決辦法:

$ git remote rm origin

然后在執行:$ git remote add origin git@github.com:defnngj/hello-world.git 就不會報錯誤了

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

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

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!