Git分布式文件管理工具與使用GitHub托管項目

jopen 10年前發布 | 19K 次閱讀 Git 版本控制系統

Git是一個分布式的版本控制系統,GitHub可以托管各種git庫,并提供一個web界面,但與其它像 SourceForge或Google Code這樣的服務不同,GitHub的獨特賣點在于從另外一個項目進行分支的簡易性。為一個項目貢獻代碼非常簡單︰首先點擊項目站點的“fork”的按 鈕,然后將代碼檢出并將修改加入到剛才分出的代碼庫中,最后通過內建的“pull request”機制向項目負責人申請代碼合并。

1、下載Git客戶端:
http://code.google.com/p/msysgit/downloads/list
2、使用Git客戶端設置Git:

可以參考:https://help.github.com/articles/set-up-git

設置用戶名:

$ git config --global user.name "Your Name Here" # Sets the default name for git to use when you commit

設置Email,可以不用真實的Email,只是作為一個標示:

$ git config --global user.email "your_email@youremail.com" # Sets the default email for git to use when you commit

設置密碼緩存時間:

$ git config --global credential.helper cache# Set git to use the credential memory cache $ git config --global credential.helper 'cache --timeout=3600'' # Set the cache to timeout after 1 hour (setting is in seconds)
3、在服務器上創建一個倉庫:

可以參考:https://help.github.com/articles/create-a-repo

4、初始化本地倉庫:
$ mkdir ~/Hello-World# Creates a directory for your project called "Hello-World" in your user directory $ cd ~/Hello-World# Changes the current working directory to your newly created directory $ git init# Sets up the necessary Git files # Initialized empty Git repository in /Users/you/Hello-World/.git/
5、添加文件:
$ touch README# Creates a file called "README" in your Hello-World directory
6、提交文件到本地倉庫:
$ git add README# Stages your README file, adding it to the list of files to be committed $ git commit -m 'first commit'' # Commits your files, adding the message "first commit"
7、生成SSH Key:

使用GitHub首先要創建SSH Key。SSH將用來加密本機與遠端服務器之間的通信。同時也是識別你對代碼所做的變更的方法。SSH Key可以使用Git命令行來產生。首先打開Git Bash命令行,輸入:

ssh-keygen -C "username@email.com" -t rsa

說明:username@email.com 為你初始化Git的設置的Email地址。

之后Git Bash命令行中,會進行一些提示:

保存位置:注意rsa key pair要生成到root directory: ~/.ssh/目錄下,如生成到C:\Users\arthinking\.ssh\id_rsa.pub。
pass phrase:如果本機安全,也可以不用輸入。

找到生成的id_rsa.pub文件,把里面的內容復制到GitHub -> Account Settings -> SSH Keys –>Add SSH key的key輸入框中,標題自定義,進行添加一個SSH Key。

8、把本地倉庫提交到服務器:
$ git remote add origin git@github.com:username/Hello-World.git# Creates a remote named "origin" pointing at your GitHub repo $ git push origin master# Sends your commits in the "master" branch to GitHub

注意,這里的Hello-World.git是根據你在服務器上創建的倉庫名稱決定的,如果服務器創建了一個Itzhai倉庫,則這里為Itzhai.git。

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