歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> GitHub入門教程 Hello World for GitHub

GitHub入門教程 Hello World for GitHub

日期:2017/2/28 13:46:19   编辑:Linux教程

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 repositories, branches, commits, 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

第一步.創建一個庫

A 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

GitHub 的詳細介紹:請點這裡
GitHub 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved