译自:《GitHub Guides》
时间:2018-2-27
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!
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
Open and merge a pull request
Hello World 项目在计算机编程里有着悠久传统。当你开始学习新的东西,这往往作为一个简单的练习可以让你快速了解。让我们在GitHub中开始吧!
你将学会如何:
1.创建和使用存储库
2.启动和管理一个新分支
3.更改一个文件,把他们放入GitHub作为一个历史根据
4.打开并合并一个上传的请求
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 repositories, branches, commits, 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?
是一个用作版本控制和协作沟通的代码托管平台。它让你与别人无论何地都可以一起做项目。本教程教你GitHub的要领比如:仓库(存放处),分支机构,提交,获取请求。你将创建一个属于你自己的“Hello World”的存放处,学习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).
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.com帐户,互联网可接入。你不需要知道如何编写代码,如何使用命令行,或安装Git(版本控制软件是一个内置的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 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.
步骤1.创建一个存储库(版本库、仓库)
存储库通常用于组织单个项目。存储库可以包含文件夹和文件、图像、视频、电子表格和数据集——任何你的项目所需要的。我们建议包含一个自述文件或一个包含关于您的项目信息的文件。GitHub可以很容易地添加一个同时您创建新的库。它还提供其他常见选项,如许可证文件。
你的“helloworld仓库”是一个你存放想法、资源、甚至与他人分享和讨论事物的地方。
To create a new repository
In the upper right corner, next to your avatar or identicon, click
and then selectNew repository.
Name your repository hello-world.
Write a short description.
Select Initialize this repository with a README.
Click Create repository.
创建新的存储库
在右上角,在你的头像或识别图标边上,点击
然后选择新的存储库。
给存储库命名“hello world”。
写一个简短的描述。
选择:Initialize this repository with a README.(用README初始化存储库)
点击: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.
步骤2.创建一个分支
分支,是在工作于一个存储库下的同时创建的不同版本时的体现。
默认情况下,您的存储库有一个名为Master(主)的分支,它被认为是最终分支。我们在保证让他们成为最终版之前,用分支来做实验和编辑。
When you create a branch off the master branch, you’re making a copy, or snap shot, of masteras 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.
This diagram shows:
1.The master branch.
2.A new branch called feature(because we’re doing ‘feature work’ on this branch)
3.The journey that feature takes before it’s merged(融合) into master
当你从主分支创建一个分支时,你正在复制一个拷贝,或者是快照,就像它在那个时间点一样。如果有人在您的分支工作时对主分支进行了更改,您可以将这些更新拖进去。
这个图表显示:
1.一个主进程
2.一个叫做特性的新分支(因为我们在这个分支上做了“功能工作”)
3.一段将功能特性在合并到主进程之前所进行的旅程
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 their branch into master.
你保存过不同版本的文件吗?像:
story.txt
story-joe-edit.txt
story-joe-edit-reviewed.txt
分支机构在GitHub存储库里完成类似的目标。
在GitHub上,我们的开发人员,作家,设计师用分支让bug修复和功能工作从我们的主分支上分离开来。当更改准备就绪时,它们将分支合并到主目录中。
To create a new branch
Go to your new repository hello-world.
Click the drop down at the top of the file list that says branch: master.
Type a branch name,readme-edits, into the new branch text box.
Select the blue Create branch box or hit “Enter” on your keyboard.
创建新分支
去你的新存储库“hello world”。
单击下拉框的文件列表顶部,表示分支:主流程。
命名一个分支名称“readme-edits”,输入到新的分支文本框中。
选择蓝色创建分支框或单击键盘上的“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.
On GitHub, saved changes are called commits. Each commit has an associated commit 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.
好极了!现在,您在您的readme-edits分支的代码视图中,这是一个主副本。让我们做一些编辑。
在GitHub上,保存的变化称为保证(版本记录)。每个版本记录都有一个关联的提交消息,这是解释为什么做出了特定更改的说明。提交信息时对每一次改版做了一次历史快照,因此其他参与者可以理解您所做的工作和原因。
Make and commit changes
Click theREADME.md file.
Click the pencil icon in the upper right corner of the file view to edit.
In the editor, write a bit about yourself.
Write a commit message that describes your changes.
Click Commit changes button.
作出并提交更改
点击readme.md文件。
单击文件视图右上角的铅笔图标进行编辑。
在编辑器中,写一点关于你自己的文章。
编写描述您的更改的提交消息。
单击Commit changes 按钮。
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.
这些更改将只对readme-edits 分支下的README文件生效,所以现在这个分支包含与主流程不同的内容。
Step 4. Open a Pull Request
Nice edits! Now that you have changes in a branch off of master, you can open apull request.
Pull Requests are the heart of collaboration on GitHub. When you open apull request, you’re proposing(提议、建议) your changes and requesting that someone review and pull in your contribution and merge them into their branch. Pull requests show diffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.
做的好极了!既然,您已经改变了一个主干的分支,你可以打开一个pull请求。
pull请求协作是GitHub上合作工作的核心。当你打开一个pull的请求,表示你提出了你的更改,并且邀请其他人参与评审,然后拉着你的贡献并融合到他们的分支中去。pull请求可以从从分支的内容显示出差别或差异。这些变化,添加和删减将用绿色和红色表示。
As soon as you make a commit, you can open a pull request and start a discussion, even before the code is finished.
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.
一旦你做出了建议,你甚至可以在代码完成之前开一个拉请求并开始讨论。
通过使用GitHub提到的系统拉你的请求消息,你可以向特定的人或团队获取反馈,无论他们在大厅或10个时区以外。
您甚至可以在自己的存储库中打开拉请求并合并它们。
这是一种很好的方式来学习GitHub流程,在你为更大的项目工作之前。
Open a Pull Request for changes to the README
更改readme时,打开pull 请求
Click the Pull Request tab, then from the Pull Request page, click the greenNew pull request button.
单击 Pull Request 按钮,然后从拉请求页,单击绿色的New pull request 按钮。
In theExample Comparisons box, select the branch you made,readme-edits, to compare with master(the original).
在示例比较框中,选择您创建的分支,readme-edits,与主(原件)进行比较。
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 请求一个标题,并写一个简短的描述你的变化。
When you’re done with your message, clickCreate pull request!
Tip: You can useemojianddrag and drop images and gifsonto comments and Pull Requests.
完成消息后,单击“Create pull request”!
提示:你可以使用表情符号和图片拖放图片或gif到评论中去,然后pull请求。
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.
Click the green Merge pull requestbutton to merge the changes into master.
Click Confirm merge.
Go a head and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.
在这最后一步中,是时候把你的更改放在一起了——将你的 readme-edits分支合并到主流程中。
单击绿色Merge pull request按钮,将更改合并到主目录中。
单击确认合并Confirm merge.。
继续删除分支,因为它的更改已被合并,在紫色框中使用了删除分支按钮。
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
庆祝!
完成本教程,你已经学会了如何创建一个项目并在GitHub上做一个拉的要求!
以下是你在本教程中完成的内容:
创建了一个开源库
开始一个新的分支和管理
改变一个文件并提交这些更改GitHub
打开和合并拉请求
Take a look at your GitHub profile and you’ll see your newcontribution squares!
To learn more about the power of Pull Requests, we recommend reading theGitHub Flow Guide. You might also visit GitHub Exploreand get involved in an Open Source project
Tip: Check out our otherGuides,YouTube ChannelandOn-Demand Trainingfor more on how to get started with GitHub.
要在你的GitHub的简介一看,你会看到你的新贡献广场!
了解更多关于拉要求的权力,我们推荐阅读GitHub导流。你也可以访问GitHub的探索和参与的一个开源项目中去
提示:查看我们的其他指南,YouTube频道和点播培训更多关于如何开始使用GitHub。