標籤:github
安裝Ubuntu上安裝Git
sudo apt-get install git
Windows上安裝Git
msysgit是Windows版的Git,從http://msysgit.github.io/下載,然後按預設選項安裝即可。安裝完成後,在開始菜單裡找到”Git”|”Git Bash”,蹦出一個類似命令列視窗的東西,就說明Git安裝成功!
配置
開啟命令列,輸入如下代碼:
git config --global user.name "YOUR NAME"git config --global user.email "YOUR EMAIL ADDRESS"
注意git config命令的--global參數,用了這個參數,表示你這台機器上所有的Git倉庫都會使用這個配置,當然也可以對某個倉庫指定不同的使用者名稱和Email地址。
建立倉庫
- 點擊GitHub頁面右上方的“+”,然後點擊“New repository”。
- 輸入倉庫的名稱及其描述資訊。
- 選擇倉庫是公開的還是私人的(只允許付費使用者建立)。
- 選擇”Initialize this repository with a README.”。
- 點擊”Create repository”。
也可從命令列輸入mkdir repoName。
提交更新
- 在倉庫的檔案清單點擊”README.md”。
- 點擊編輯按鈕,對檔案作出修改,檔案內容上方有預覽按鈕可以預覽修改效果。
- 在”Commit changges”下方輸入簡單的有意義的更新資訊。
- 點擊”Commit changes”。
最後一步除了”Commit changes”之外還有” Create a new branch for this commit and start a pull request”選項,可以用此選項建立一個pull request。管理員即可點擊”Merge pull request”合并結果。如果從命令列合并,步驟如下:
Step 1: From your project repository, bring in the changes and test.
git fetch origin
git checkout -b chinaeagle001-patch-1 origin/chinaeagle001-patch-1
git merge master
Step 2: Merge the changes and update on GitHub.
git checkout master
git merge --no-ff chinaeagle001-patch-1
git push origin master
Fork A Repo建立分支的例子
- On GitHub, navigate to the octocat/Spoon-Knife repository.
- Fork buttonIn the top-right corner of the page, click Fork.
同步分支建立分支的本地複製。
- 在GitHub頁面,導航到你的分支,複製分支的URL。
- 開啟命令列,輸入:
git clone https://github.com/YOUR-USERNAME/Spoon-Knife。
- 斷行符號,本地複製建立完畢。
配置Git使分支與原始的倉庫同步
- On GitHub, navigate to the octocat/Spoon-Knife repository.
- 複製原始倉庫的URL。
-
在命令列輸入git remote -v並點擊斷行符號,可以看到當前配置的你的分支的遠程倉庫。
git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
-
輸入git remote add upstream,然後粘貼複製的URL並點擊斷行符號。
git remote add upstream https://github.com/octocat/Spoon-Knife.git
- 此時,再次輸入
git remote -v,可以看到如下資訊:
git remote -v
# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
# upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
# upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
現在,就可以通過少量的Git命令使分支與原始倉庫同步。
git fetch upstream
git checkout master
git merge upstream/master
The sky’s the limit with the changes you can make to a fork, including:
- Creating branches: Branches allow you to build new features or test out ideas without putting your main project at risk.
- Opening pull requests: If you are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
GitHub使用筆記