GitHub教程(一) 使用指南

剛進公司上班的時候,技術總監讓我熟悉一下Git(分佈式版本控制工具)操做命令和GitHub(代碼託管平臺),說實話以前我也沒有具體使用過Git工具,可是GitHub我仍是註冊過帳號的。在練習將本地倉庫(Git版本庫)上傳到遠程版本庫時,也順帶着學習了GitHub的官方指南。
而後還得和您說聲抱歉,這份資料是我本身學習GitHub時使用的教程,在博客中我也不打算再把這篇官方指南一字不落地翻譯成中文文檔。
 
 

The  Hello World project is a time-honored(歷史悠久的) tradition in computer programming. It is a simple exercise that gets you started when learning something new. Let’s get started with GitHub!  譯者注:若是您想了解Hello World的起源,能夠參考這篇文章 程序員,你知道Hello World的歷史麼?
 

You’ll learn how to:git

  • Create and use a repository             //  建立並使用倉庫(版本庫)
  • Start and manage a new branch      //  啓動並管理一個新分支
  • Make changes to a file and push them to GitHub as commits    //  修改一個文件並將這些變動做爲 commit push到GitHub上 
  • Open and merge a pull request       //  打開並merge一個pull request

譯者注:有些GitHub的專有名詞沒有翻譯,不是由於我懶得翻。以本人愚見,這些專有名詞就算翻譯過來也沒有多大意思,原汁原味兒的比較好,實在不清楚能夠去金山詞霸查查具體含義。程序員

What is GitHub?
GitHub is a code hosting(託管) platform for version control and collaboration(協同合做). It lets you and others work together on projects from anywhere.

This tutorial teaches you GitHub essentials like repositoriesbranchescommits, and Pull Requests. You’ll create your own Hello World repository and learn GitHub’s Pull Request workflow(工做流), a popular way to create and review code.github

No coding necessary

To complete this tutorial, you need a GitHub.com account and Internet access. You don’t need to know how to code, use the command line, or install Git (the version control software GitHub is built on).   // 雖然教程說學習GitHub沒必要安裝Git,使用命令行操做,可是仍是建議讀者稍微熟悉一下Git命令分佈式

Tip: Open this guide in a separate browser window (or tab) so you can see it while you complete the steps in the tutorial.ide

 

Step 1. Create a Repository
repository is usually used to organize a single project. Repositories can contain folders and files, images, videos, spreadsheets(電子表格), and data sets – anything your project needs. We recommend including a  README, or a file with information about your project. GitHub makes it easy to add one at the same time you create your new repository.  It also offers other common options such as a license file.

Your hello-world repository can be a place where you store ideas, resources, or even share and discuss things with others.工具

To create a new repository

  1. In the upper right corner(右上角), next to your avatar or identicon, click  and then select New repository.
  2. Name your repository hello-world .
  3. Write a short description.
  4. Select Initialize this repository with a README.

 Click Create repository學習

 

Step 2. Create a Branch
Branching(n, 分支) is the way to work on different versions of a repository at one time.     //  分支是一種在同一時間運行同一倉庫不一樣版本的方式

譯者注:分支和快照是相似的概念,快照指的是在某一時間點的數據狀態集合,至關於一種特殊的鏡像文件ui

By default your repository has one branch named master which is considered to be the definitive branch. We use branches to experiment and make edits before committing them to master.this

 
When you create a branch off(脫離) the master branch, you’re making a copy, or snapshot, of master as(與此同時) it was at that point in time. If someone else made changes to the  master branch while you were working on your branch, you could pull in(吸取) those updates.
譯者注:在實際團隊項目中,咱們在push更新代碼前須要先把遠程版本庫中的代碼更新pull下來。

This diagram shows:idea

  • The master branch   //  主分支
  • A new branch called feature (because we’re doing ‘feature work’ on this branch)   //  功能分支
  • The journey that feature takes before it’s merged into master   

        // 從master分支脫離出來到被merge到master分支以前,feature分支會有一段單獨歷程

     

 

Have you ever saved different versions of a file? Something like:

  • story.txt 
  • story-joe-edit.txt 
  • story-joe-edit-reviewed.txt 

Branches accomplish similar goals in GitHub repositories.    // Branches在GitHub倉庫中完成類似的目標---儲存一個文件的不一樣版本

Here at GitHub, our developers, writers, and designers use branches for keeping bug fixes and feature work separate from our master (production) branch. When a change is ready, they merge their branch into master.   譯者注:master分支保存就是往後要作出來的真正production

To create a new branch

  1. Go to your new repository hello-world .    
  2. Click the drop down at the top of the file list that says branch: master.
  3. Type a branch name, readme-edits , into the new branch text box.
  4. Select the blue Create branch box or hit 「Enter」 on your keyboard.
Now you have two branches,  master  and  readme-edits. They look exactly the same, but not for long! Next we’ll add our changes to the new branch.  
// master分支和readme-edits分支看起來相同,可是這種相同不會保持好久,由於咱們很快將會對新分支(readme-edits)進行修改

譯者注:這裏的readme-edits分支就是上文中提到的feature分支,屬於功能分支,用於增長某個模塊功能 

 
Step 3. Make and commit changes
Bravo(喝彩)! Now, you’re on the code view for your  readme-edits branch, which is a copy of  master. Let’s make some edits.
On GitHub, saved changes are called commits. Each commit has an associatedcommit message(提交相關消息) , which is a description explaining why a particular change was made. Commit messages capture the history of your changes, so other contributors can understand what you’ve done and why.
// 在GitHub上,"保存變動"用專業名詞叫 commit(提交),每一個commit必須有相應的message用於描述爲何須要變動

Make and commit changes

  1. Click the README.md file.
  2. Click the  pencil icon in the upper right corner of the file view to edit.
  3. In the editor, write a bit about yourself.
  4. Write a commit message that describes your changes.
  5. Click Commit changes button.

These changes will be made to just the README file on your readme-edits branch, so now this branch contains content that’s different from master

 
Step 4. Open a Pull Request
Nice edits! Now that you have changes in a branch off of  master, you can open a  pull request(拉回請求,請求合併到主幹master).

Pull Requests are the heart of collaboration(協同工做的核心) on GitHub. When you open a pull request, you’re proposing your changes and requesting that someone review and pull in your contribution and merge them into their branch. Pull requests sho diffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.      // pull requests後master分支變化會用不一樣顏色顯示,增長內容用綠色標識,刪除內容用紅色表示

As soon as you make a commit, you can open a pull request and start a discussion, even before the code is finished.   // commit後就會discussion模塊出現

By using GitHub’s @mention system in your pull request message, you can ask for feedback from specific people or teams, whether they’re down the hall or 10 time zones away.

You can even open pull requests in your own repository and merge them yourself. It’s a great way to learn the GitHub Flow before working on larger projects.

Open a Pull Request for changes to the README

Click on the image for a larger version

Step Screenshot
Click the  Pull Request tab, then from the Pull Request page, click the green New pull request button.

 

Select the branch you made, readme-edits, to compare with  master  (the original).

 

Look over your changes in the diffs on the Compare page, make sure they’re what you want to submit.
When you’re satisfied that these are the changes you want to submit, click the big green Create Pull Requestbutton.

 

Give your pull request a title and write a brief description of your changes.

 

When you’re done with your message, click Create pull request!


Tip: You can use emoji and drag and drop images and gifs onto comments and Pull Requests.

 

Step 5. Merge your Pull Request

In this final step, it’s time to bring your changes together – merging your readme-edits branch into the master branch.

  1. Click the green Merge pull request button to merge the changes intomaster.
  2. Click Confirm merge.
  3. Go ahead and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.

Celebrate!

By completing this tutorial, you’ve learned to create a project and make a pull request on GitHub!   

Here’s what you accomplished in this tutorial:

  • Created an open source repository
  • Started and managed a new branch
  • Changed a file and committed those changes to GitHub
  • Opened and merged a Pull Request

Take a look at your GitHub profile and you’ll see your new contribution squares!

If you want to learn more about the power of Pull Requests, we recommend reading the GitHub Flow Guide. You might also visit GitHub Explore and get involved in an Open Source project 


Tip: Check out our other Guides and YouTube Channel for more GitHub how-tos.

 

到此爲止,官網上面GitHub入門教程已經介紹完了,相信經過您不屑的努力必定已經學會這些GitHub基礎操做。若是想要進一步得學習,推薦GitHub Flow Guide(GitHub流程指南,交互式得操做使得讀者更容易理解如何脫離分支、合併分支等概念)。

做爲Git系列教程中遠程倉庫篇---GitHub系列教程的第一篇文章,本文就係統地介紹了GitHub使用者該掌握的基礎內容。對系列教程感興趣的同窗,能夠選擇訂閱我博客,我會在工做之餘持續更新,與大夥共同提升(技術層面和英文層面),嘻嘻。

相關文章
相關標籤/搜索