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’在计算机编程界是一个历史悠久的传统项目。当你学习一个新的编程知识的时候,它是带你入门的一个很好的练习。我们一起开始学习 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
在这里你会学到:
- 如何创建和使用一个代码版本库
- 如何启动和管理一个新的代码分支
- 如何修改一个文件并把它们提交到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.
GitHub 是一个代码版本控制和协作的平台。它能够使你和他人无论在什么地方都能够一起去开发一个项目。
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.
这个辅助教程教你一些例如代码库、分支、托管、处理请求等。你将会创建你自己的’Hello World’ 代码库,并且学习GitHub’s 处理请求的工作流,它是一个非常流行的创建和查看代码的工具。
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.com 的账号。你不需要知道如何编程、使用命令行、或者安装Git(GitHub是建立在这个版本控制软件之上)。
Tip: Open this guide in a separate browser window (or tab) so you can see it while you complete the steps in the tutorial.
注意:把这个教程在一个单独的窗口(或者tab)中打开,这样当你按照步骤完成项目的时候你就可以看到你创建代码库了。
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.
一个代码库只能用于组织管理一个项目。代码库可以包含文件夹和文件、图片、视频、电子表格、数据集——你项目需要的任何东西。在你创建新的代码库的时候你就可以把这些东西添加进去,GitHub 是这一切变得特别容易。 它也提供了其他公共的选项,比如说项目协议文件。
Your hello-world
repository can be a place where you store ideas, resources, or even share and discuss things with others.
你的 Hello-world
代码库可以存放你的创意、资源,甚至能够与他人分享讨论一些事情。
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.
a. 在你主页界面的右上角,点击‘+’ ,选择‘New repository‘。
b. 把你的代码库命名为hello-world
c. 写一个简单的描述。
d. 选择”Initialize this repository with a README” (代码库初始化说明)
Click Create repository.
点击 ” Create repository” 创建代码库
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 were working on your branch, you could pull in those updates.
当你创建一个 master
的分支的时候,你是对 master
的一个时点 进行的一个复制或快照。如果当你在修改你的分支的时候,别人也在master
的一个分支上修改,你可以获取到他们的修改内容。
This diagram shows:
如图图示
- 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
分支
- 名叫 feature
的分支(因为我们正在在这个主分支上做‘重要的功能工作’)
- 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.
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
.
在GitHub 上,我们的开发工程师、编辑、设计师在主分支(生产系统)以外使用分支来修复漏洞或新功能开发。当一个漏洞或者新功能测试没有问题后就会把分支合并到主分支中。
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 hit “Enter” on your keybord.
a. 找到你刚促创建好的 ‘hello-world’项目.
b. 点击右边中间 ‘Branch: master’ 下拉菜单
c. 在分支输入框中输入 ‘readme-edits’
d. 填写完成后选择Create branch,然后回车
如下所示:
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.
现在你有两个分支,主分支和新添加的readme-edits分支,它们现在看起来完全一样,分支readme-edits修改后就不一样了。接下来我们会修改分支readme-edits。
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 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.
在GitHub上,保存修改叫做提交。每个提交都会有一个关联的提交信息(由提交者和版本控制系统共同完成),这个关联的提交信息用于解释这一块代码为什么要修改。这个关联的提交信息能够捕捉到当前版本和历史版本之间的变化,这样其它的代码贡献者才能够知道和理解你修改了什么以及为什么要这样修改。
Make and commit changes
修改分支代码库并提交
1. Click the READEME.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.
a. 点击 README.md
文件。
b. 点击 ‘README.md’ 文件右上面的铅笔图标进行编辑
c. 在编辑界面,写一些关于你自己的一些信息和这个项目的一些信息。
d.写一些你修改的地方以及为什么修改。
e.点击提交修改按钮。
如下图所示:
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’ 文件,现在你修改后的这个分支就于master
分支有所不同了。
Nice edits! Now that you have changes in a branch off of master, you can open a pull request.
修改的很好! 现在你已经在master
的一个分支上做好了修改,你可以针对你的修改向项目内的所有人发起修改提交合并请求。
(就是向项目创建者,还有其他贡献者发起一个请求,希望你的修改能够合并添加到项目中去,即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 show diffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.
Pull Requests 是 GitHub 上各个贡献者协作的核心。当你打开一个Pull Request的时候,你是希望别人能够针对你的修改作出回复,同步你修改或新增的代码,最好能够把这些代码合并到他们的分支中。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 供大家讨论,直到代码结束(合并到master中,或者最终没有被采纳)。
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.
通过使用 GitHub’s 的@metion 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 Requests 并把一些修改的代码合并到你的代码中。 在开发稍微大的项目之前,这不失为一个了解GitHub 工作流的好方法。
Open a Pull Request for changes to the README(为修改的README 打开一个Pull Request)
Click on the image for a large version
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.
小贴士:你可以把emoji 表情,也可以把图片或者gifs 动画图片拖放到评论的地方和Pull Requests上面.
In this final step, it’s time to bring your changes together -merging your readme-edits
branch into the master
branch.
最后,要把你修改的代码即 readme-edits
分支和 master
进行合并。
1. Click the green Merge pull request button to merge the changes into master
.
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.
a.点击 绿色的Merge pull request 按钮把你修改的代码合并到主分支master
之中
b. 点击 确认合并 按钮
c. 去前一页删除分支,如果你修改的代码已经合并到主分支中,Delete branch (删除分支)按钮会在紫色框中显示。
如下图所示:
By completing this tutorial,you’ve learned to create a project and make a pull request on GitHub!
看完这个教程后,你就学会如何在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 上
- 打开和合并一个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 Requests 的伟大力量,我们建议你阅读一下GitHub 的工作流程指导。你也可以探索一下 GitHub 的开源项目列表,并参与到其中一个开源项目中。
Tip: Check out our other Guides and YouTube Channel for more GitHub how-tos.
小贴士:去我们另一个关于GitHub 的指南 和 YouTube 频道 ,进一步了解GitHub。