Ubuntu linux github & git使用

來源:互聯網
上載者:User

 

Github 使用指南!(下文針對linux系統而言,特指ubuntu系統)

第一步:下載安裝Git。

使用新立得軟體包管理工具(Synaptic Package Manager)安裝最新版本的git。推薦選擇安裝git-core,git-gui,git-doc。

第二步:設定SSH Keys

github使用ssh keys來確保你的電腦與github的串連有安全性。設定過程很簡單。

但是有幾個步驟。

步驟一:檢查已有的ssh keys。

$ cd ~/.ssh

如果提示說,沒有這樣的檔案或者目錄。(No such file or directory) 則跳到步驟三。否則繼續。

步驟二:備份已有的ssh keys。

步驟三:產生一個新的 ssh key。

我的產生過程如下:

banxi1988@banxi:~$ ssh-keygen -t rsa -C "banxi1988@gmail.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/home/banxi1988/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Passphrases do not match. Try again.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/banxi1988/.ssh/id_rsa.

Your public key has been saved in /home/banxi1988/.ssh/id_rsa.pub.

The key fingerprint is:

0c:a5:4d:a7:d8:e8:42:b2:5c:75:d0:4c:e5:ff:6a:7f
banxi1988@gmail.com

The key's randomart image is:

+--[ RSA 2048]----+

| o==.o |

| . Xo+ |

| . o = + . |

| . = . o . |

| o . . S . |

| . . |

| . |

| .. E|

| ..... |

+-----------------+

banxi1988@banxi:~$

步驟四:

在gitHub裡單擊賬戶設定。點擊 SSH 公開金鑰 ,點擊添加另一個公開金鑰。

開啟前面產生的id_rsa.pub 檔案。(可能要顯示隱藏檔案才能看到用gedit或者其它的編輯器開啟。

注意不要編輯,添加空格或者換行。)

然後把裡面的內容複寫粘貼到下面的key輸入欄中。

步驟五:測試一下。

banxi1988@banxi:~$ ssh
git@github.com

/etc/ssh/ssh_config: line 20: Bad configuration option: X11Forwrding

/etc/ssh/ssh_config: terminating, 1 bad configuration options

banxi1988@banxi:~$

After modify the ssh_config.中間要求輸入上面輸入的passphrase。

banxi1988@banxi:~$ 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.

PTY allocation request failed on channel 0

Hi banxi1988! You've successfully authenticated, but GitHub does not provide shell access.

Connection to github.com closed.

banxi1988@banxi:~$

 

步驟六:設定git的個人資訊。

1. 設定使用者名稱和email。git使用這個來驗證每個提交者。除此之外github會使用這些資訊來與你的github帳號相聯絡。下面的名字應該是你真實的名字。而不是要GitHub的使用者名稱。

banxi1988@banxi:~$ git config --global user.name "Li HaiZhen"

banxi1988@banxi:~$ git config --global user.email "banxi1988@gmail.com"

banxi1988@banxi:~$

2. 設定GitHub的指令環。

有些工具不使用ssh來串連。為了使用這些工具。你應該找出配置好你的API Token。

在GitHub上點擊。帳號設定(Account Settings) ,然後點擊 帳號管理(Account Admin)。

在API Token一欄裡有你的API ToKen。

在命令列下運行下面的代碼。

banxi1988@banxi:~$ git config --global github.user banxi1988

banxi1988@banxi:~$ git config --global github.token e5ebe68d43d9820ed8d05a3d2633d7f3

banxi1988@banxi:~$

上面使用的user是指GitHub的使用者名稱了。

最後:恭喜你!你已經正確的設定了git和gitHub。

接下來。要做的就是。1. 建立一個倉庫。2. Fork 一個倉庫。 3.社區化。

 

第二節:建立一個倉庫(Create A Repo Repositories)

直接在自己的登入後進入github.com首頁就可以看到, 下面一欄有四步.用來建立Repository.

直接填入項目名稱就可以了.其它的可以不填.要填,這個表單也足夠自解釋了.

建立後之後.會跳轉到一個頁面.其中有指示接下來該怎麼做的.

如下:

git@github.com:banxi1988/tasteHibernate.git

 
接下來給你自己的項目建立一個基本的Readme檔案吧.

詳細操作過程如下:

Global setup:
 Download and install Git
  git config --global user.name "banxi1988"
  git config --global user.email banxi1988@gmail.com
        Next steps:
  mkdir tasteHibernate
  cd tasteHibernate
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin
git@github.com:banxi1988/tasteHibernate.git
  git push -u origin master
      Existing Git Repo?
  cd existing_git_repo
  git remote add origin
git@github.com:banxi1988/tasteHibernate.git
  git push -u origin master
      Importing a Subversion Repo?
  Click here
      When you're done:
  Continue

banxi1988@banxi:~/github/tasteHibernate$ git init

Initialized empty Git repository in /home/banxi1988/github/tasteHibernate/.git/

banxi1988@banxi:~/github/tasteHibernate$ touch README

banxi1988@banxi:~/github/tasteHibernate$ vi README

banxi1988@banxi:~/github/tasteHibernate$ git add README

banxi1988@banxi:~/github/tasteHibernate$ git commit -m 'first commit'

[master (root-commit) 6ec8aae] first commit

1 files changed, 6 insertions(+), 0 deletions(-)

create mode 100644 README

banxi1988@banxi:~/github/tasteHibernate$ git remote add origin
git@github.com:banxi1988/tasteHibernate.git

banxi1988@banxi:~/github/tasteHibernate$ git push origin master

ERROR: banxi1988/tasteHibernate.git doesn't exist. Did you enter it correctly?

fatal: The remote end hung up unexpectedly

banxi1988@banxi:~/github/tasteHibernate$ git push -u origin master

Counting objects: 3, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 383 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To git@github.com:banxi1988/tasteHibernate.git

* [new branch] master -> master

Branch master set up to track remote branch master from origin.

banxi1988@banxi:~/github/tasteHibernate$

 

關於Git的命令請參見Git手冊.

現在我們已經可以建立了一個庫了.建立了一個檔案,並且提交了.並且把它推向了github.接下來我們將做什麼呢?

第三節: Fork A Repo

有些時候你發現自己想要為別人的項目做貢獻.或者希望來使用別人的項目做為自己的起點.也就稱之為Fork.
 
Fork一個項目. 在你想fork的項目的首頁.找到fork按鈕.點擊.

接下來設定你本地倉庫.

A . 複製項目.

$ git clone git@github.com:username/projectname.git

B. 遠程配置.

當你複製了一個項目之後.它有一個預設的remote.叫做.origin.這是指你是在github上fork的.而不是在原來的倉庫.為了跟蹤原本的倉庫,你需要添加另一個叫做upstream的選項.

$cd projectname

$ git remote add upstream git://github.com/username/projectname.git

$ git fetch upstream

 
 
接下來.你要做的就是.

A. 推送提交.

一旦你做出了某些提交到你fork的倉庫裡,你可能想要將其推送到你fork的項目去.你要做就跟平常的項目一樣.

$git push origin master

 
接收upstream 變更.

如果你fork的那個原來的倉庫改變了,你可以使用下面的命令來更新你fork到本地的倉庫.

$ git fetch upstream

$ git merge upstream/master

後面的更多使用指南請參考相關文檔.例如建立分支等.

 

本指南是由banxi1988根據github提供的協助.進行的實踐之後,翻譯過來的.

由於本人水平有限.所以翻譯得不好,你可以向我提意見或者直接到github裡面的去看協助.

 

 

參考連結:

http://blog.chinaunix.net/uid-26185912-id-3327885.html

 

http://www.th7.cn/system/lin/2012/06/04/23044.shtml

 

http://luozhaoyu.iteye.com/blog/1461705

 

http://blog.chinaunix.net/uid-25885064-id-2747803.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.