首頁 > 軟體

GitHub入門教學 Hello World for GitHub

2020-06-16 17:26:43

Intro                              1.簡介

  • What is GitHub?           2.什麼是github?
  • Create a Repository     3.建立一個庫
  • Create a Branch            4.建立一個分支
  • Make a Commit            5.做一次提交
  • Open a Pull Request     6.提出一次Pull Request
  • Merge Pull Request      7.合併Pull Request

 

前言:這個是官方教學,看完覺得寫的挺好的,於是翻譯一下給需要的人,本人才疏學淺,有翻譯的不到位的地方歡迎指正.

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

在計算機程式設計領域,每當學習一個新的東西的時候,開始都會建立一個HelloWorld工程,這是一個歷史悠久的傳統,那麼,就讓我們也通過HelloWorld開始我們的GitHub之旅

started with GitHub!

吧!

 

You’ll learn how to:

你將學會如何:

  • Create and use a repository
  • 建立並使用一個庫
  • Start and manage a new branch
  • 開始並管理一個新的分支
  • Make changes to a file and push them to GitHub as commits
  • 修改一個檔案並把這項修改上傳到GitHub
  • Open and merge a pull request
  • 開啟並合併一次Pull Request

 

What is GitHub?

什麼是GitHub

GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.

GitHub是一個非常方便進行版本控制和聯合開發的程式碼託寄平台.

This tutorial teaches you GitHub essentials like repositoriesbranchescommits, and Pull Requests. You’ll create your own Hello World repository and

這個教學將會教你幾個關於GitHub的要點,像庫,分支,更新和Pull Request.你將會建立你自己的HelloWorld庫並且學會GitHubPull Request的工作流程,對建立和回顧程式碼來說,

learn GitHub’s Pull Request workflow, a popular way to create and review code.

這將非常方便,這種程式碼管理方式很受歡迎.

 

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

為了完成這個教學,你僅僅需要一個GitHub賬戶和一台能上網的電腦.你不需要知道如何寫控制Git的程式碼,使用命令列程式或者安裝Git(GitHub的版本控制軟體)

Git (the version control software GitHub is built on).

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

提醒:你可以把這個教學和GitHub的其他網頁以不同的視窗或標籤開啟來更方便的檢視

 

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

我們建議你的專案裡面一定要包括一個readme或者說一個包含關於專案資訊的檔案.GitHub會在你建立一個新的庫的時候提供建立這個readme檔案的選項,這非常方

same time you create your new repository. It also offers other common options such as a license file.

便,同時GitHub也提供了例如許可協定檔案的其他選項.

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

你的HelloWorld庫是一個可以存放想法 資源甚至是一個和其他人分享和討論事情的地方.

 

To create a new repository

建立一個新的庫

  1. In the upper right corner, next to your avatar or identicon, click  and then select New repository.1.在右上角,點選加號選擇New repository.
  2. Name your repository hello-world.2.給庫命名hello-world
  3. Write a short description.3.寫一下這個庫的簡要說明
  4. Select Initialize this repository with a README.4.選擇生成一個帶README的庫

 

Click Create repository

點選Create repository按鈕.

 

Step 2. Create a Branch

第二步.建立一個分支

Branching is the way to work on different versions of a repository at one time.

分支是一種可以同時在不同版本上工作的方法.

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.

預設情況下你新建的庫裡面會有一個叫做master的??支,在和master分支融合之前,我們通過建立其他分支來試驗和修改專案內容.

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

當你建立一個不同於master的新的分支時,就相當於把你的master分支專案複製了一份,當有人更改這個專案時,你可以選擇把這些更改作為更新加入到你的master分支專案裡.

were working on your branch, you could pull in those updates.

 

This diagram shows:

下面的這個圖展示的是:

  • The master branch
  • master分支
  • A new branch called feature (because we’re doing ‘feature work’ on this branch)
  • 一個叫做feature的新的分支(因為在這個分支上做的是不一樣的工作)
  • The journey that feature takes before it’s merged into master
  • 這就是feature分支被合併到master分支的過程

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.

在一個庫空,不同的分支其實是為了完成同一個目標.

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

在GitHub,我們開發者,作家和設計師通過使用來自master的不同分支來修補bug和完成各自不同的工作. 當更新完成後,他們把這些不同的分支合併到master分支裡.

their branch into master.

 

To create a new branch

建立一個新的分支

  1. Go to your new repository hello-world.1.去HelloWorld所在的庫.
  2. Click the drop down at the top of the file list that says branch: master.2.點選branch按鈕中的下拉式選單中的master.
  3. Type a branch name, readme-edits, into the new branch text box.3.在輸入框中輸入一個新的branch名字: readme-edits,
  4. Select the blue Create branch box or hit “Enter” on your keyboard.4.點選藍色的Create Branch按鈕或者按下Enter鍵.

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.他們幾乎一樣,但是不會很久.接下來我們就要在新的分支裡加入改動.

 

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.

好極了!現在,你看到的是readme-edits分支裡的程式碼,這個程式碼是master分支的複製版.讓我們做一些更改.

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

在GitHub上,儲存改動被稱為commits.每個commit都會有一個關聯的commit資訊,commit資訊用來記錄每次更改的內容,通過這個資訊其他人能夠明白你做了什麼,為什麼做.

the history of your changes, so other contributors can understand what you’ve done and why.

 

Make and commit changes

提交一次更改

  1. Click the README.md file.1. 點選 README.md檔案
  2. Click the  pencil icon in the upper right corner of the file view to edit.2.為了編輯,點選檔案右上角的鋼筆圖示
  3. In the editor, write a bit about yourself.3.在編輯器裡,寫一些關於你的事.
  4. Write a commit message that describes your changes.4.寫一個commit說明來說明你的改動.
  5. Click Commit changes button.5.點選Commit changes按鈕.

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

 這下在你已經在你的readme-edits的分支裡做出了改動,因此現在這個分支裡已經包含著與master分支不同的內容了.

 

Step 4. Open a Pull Request

第四步.發起一個Pull Request

Nice edits! Now that you have changes in a branch off of master, you can open a pull request.

改的好,現在你已經對做了不同於master的改動,你可以發起Pull Request了.

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

在GitHub上,Pull Requests是協同合作的核心,當你發起一次Pull request時,你是在提出你的改動,是在請求別人檢查你的工作成果並把這些成果合併到他的分支中.

merge them into their branch. Pull requests showdiffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.

Pull requests 代表的不同分支的不同之處, 綠色和紅色代表著不同的含義,如:更改內容/增加內容/減少內容.

As soon as you make a commit, you can open a pull request and start a discussion, even before the code is finished.

每當你有所改動,你都可以發起一次pull request,甚至在你完成程式碼之前.

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.

通過在你的pull request資訊中使用GitHub的@mention system ,你可以從一個特定的人或團隊那裡請求反饋,不論他們離你有多遠.

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.

你甚至可以在你自己的庫里發起pull reque並合併到你的專案裡.在開始一個大專案之前,了解GitHub的這個工作流程真的非常重要.

 

Open a Pull Request for changes to the README

對README發起一個pull request

Click on the image for a larger version

 點選圖片放大

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

點選Pull Request 標籤,然後在pull request頁中點選 綠色的New pull request 按鈕.

 

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

選擇你更改過的readme-edits分支來和master分支進行比較.

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.

當你對這些所做的更改滿意並想要提交的話,點選那個大大的Create Pull Request按鈕.

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

給你的pull request起一個名字並寫一個簡單的描述

 

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

當你完成後,點選 Create pull request!


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

提示:在pull request資訊中,你可以用表情符號或拖拽圖片進去.

 

Step 5. Merge your Pull Request

第五步.合併你的Pull Request

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

最後一步了,現在是時候把你的改動合併了,把你的readme-edits分支合併到master分支裡.

  1. Click the green Merge pull request button to merge the changes intomaster. 1.點選綠色的Merge pull request 按鈕來把改動合併到master裡.
  2. Click Confirm merge.2.點選Confirm merge按鈕.
  3. Go ahead and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.

     3.現在你可以把這個分支刪掉了,因為它的改動已經被合併到master裡面了,刪除按鈕是 Delete branch,在一個紫色的框裡.

Celebrate!

慶祝吧!

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

通過完成這個教學,你已經學會如何在GitHub上建立一個專案並行起一個pull request!

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
  • 改動一個檔案並把這些改動更新到GitHub上.
  • Opened and merged a Pull Request.
  • 發起並合併一個Pull Request.

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

看一下你的GitHub檔案,你會發現你的貢獻正方形.(綠色或紅色的正方形)

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

 如果你想學習更多關於pull request的內容,我們推薦閱讀 GitHub Flow Guide. 你還可以通過存取GitHub Explore來參與到一個開源專案中去.再見.


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

提示:檢視我們的其他的指導和Youtube頻道來學習更多的教學.

GitHub 教學系列文章: 

通過GitHub建立個人技術部落格圖文詳解  http://www.linuxidc.com/Linux/2015-02/114121.htm

GitHub 使用教學圖文詳解  http://www.linuxidc.com/Linux/2014-09/106230.htm 

使用 GitHub / GitLab 的 Webhooks 進行網站自動化部署  http://www.linuxidc.com/Linux/2016-06/131993.htm

多個GitHub帳號的SSH key切換 http://www.linuxidc.com/Linux/2016-05/131080.htm

如何在同一台電腦上使用兩個GitHub賬戶 http://www.linuxidc.com/Linux/2016-05/131079.htm

利用GitHub搭建個人Maven倉庫  http://www.linuxidc.com/Linux/2016-04/130197.htm

一分鐘認識GitHub http://www.linuxidc.com/Linux/2015-11/125089.htm

分享實用的GitHub 使用教學 http://www.linuxidc.com/Linux/2014-04/100556.htm 

GitHub使用操作指南  http://www.linuxidc.com/Linux/2016-10/135782.htm


IT145.com E-mail:sddin#qq.com