原文地址:https://guides.github.com/activities/hello-world/
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(请求)
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(审查代码).
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的版本控制软件)).
Tip: Open this guide(指南) in a separate browser window(单独的浏览器窗口) (or tab(选项卡)) so you can see it while you complete(完成) the steps(步骤) in the tutorial(教程).
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 repositor(在创建新存储库的同时,GitHub可以很容易地添加一个). 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
- In the upper right corner(在右上角), next to your avatar or identicon(在你的头像或同位符旁边), click +(点击+) and then select New repository.
- Name your repository
hello-world
.(将存储库命名为hello-world) - Write a short description(简短的描述).
- Select Initialize(初始化) this repository with a README(自述文件).
Click 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 main
which is considered(考虑,视为) to be the definitive(最后的;最佳的;最权威的) branch. We use branches to experiment(尝试) and make edits before committing them to main
.
默认情况下,您的存储库有一个名为的分支main
,该分支被视为权威分支。我们使用分支进行实验并进行修改,然后再将其提交到main
。
When you create a branch off the main
branch, you’re making a copy, or snapshot(快照), of main
as it was at that point in time. If someone else made changes to the main
branch while you were working on your branch, you could pull(提取) in those updates.
当您在分支机构外创建分支机构时main
,您将main
在当时复制或快照。如果main
在您处理分支时其他人对该分支进行了更改,则可以提取这些更新。
This diagram shows:
- The
main
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(并入)main
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 main
(production) branch. When a change is ready, they merge their branch into main
.
在GitHub,我们的开发人员,编写者和设计人员使用分支来将错误修复和功能工作与main
(生产)分支分开。更改准备就绪后,他们会将分支合并到中main
。
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: main.
- 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
。 - 单击文件列表顶部的分支:main的下拉列表。
readme-edits
在新的分支文本框中输入分支名称。- 选择蓝色的“创建”分支框,或在键盘上按“ Enter”。
Now you have two branches, main
and readme-edits
. They look exactly the same, but not for long! Next we’ll add our changes to the new branch.
现在您有两个分支,main
和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 main
. Let’s make some edits.
太棒了!现在,您在readme-edits
分支的代码视图中,该视图是的副本main
。让我们进行一些编辑。
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上,保存的更改称为commits。每个提交都有一个关联的提交消息,该消息是说明为什么进行特定更改的说明。提交消息记录了更改的历史记录,因此其他贡献者可以了解您所做的事情以及原因。
Make and commit changes
- Click the
README.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
文件。 - 点击 要编辑的文件视图右上角的铅笔图标。
- 在编辑器中,写一些关于您自己的信息。
- 编写描述您所做更改的提交消息。
- 单击提交更改按钮
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 main
.
Step 4. Open a Pull Request
Nice edits! Now that you have changes in a branch off of main
, you can open a pull request.
不错的编辑!现在您已经在分支的分支中进行了更改main
,您可以打开拉取请求。
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.
拉取请求是GitHub上协作的核心。当您打开请求请求时,您是在提出更改,并要求某人检查并提取您的贡献并将其合并到其分支中。拉取请求显示两个分支中内容的差异或差异。更改,加法和减法以绿色和红色显示。
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.
通过在请求请求消息中使用GitHub的@mention系统,您可以要求特定人员或团队提供反馈,无论他们是在大厅还是在10个时区之外。
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流程的好方法。
Open a Pull Request for changes to the README打开请求更改自述文件的请求
Click on the image for a larger version点击图像查看大图
Step | Screenshot |
Click the 'n' Pull Request tab, then from the Pull Request page, click the green New pull request button.点击n “拉取请求”选项卡,然后从“拉取请求”页面中,单击绿色的“新建拉取请求”按钮。 | |
In the Example Comparisons box, select the branch you made, readme-edits , to compare with main (the original).在“示例比较”框中,选择readme-edits 要与main (原始)进行比较的分支。 | |
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 Request button.如果您对要提交的更改感到满意,请单击绿色的大的创建请求请求按钮。 | |
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 main
branch.
在最后的步骤中,是时候将您的更改集中在一起了–将readme-edits
分支合并到main
分支中。
- Click the green Merge pull request button to merge the changes into
main
. - Click Confirm merge.
- Go ahead and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.
- 点击绿色的合并拉取请求按钮,将更改合并到中
main
。 - 点击确认合并。
- 继续并删除分支,因为已经合并了其更改,请在紫色框中使用“删除分支”按钮。
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
- 打开并合并拉取请求
Take a look at your GitHub profile and you’ll see your new contribution squares!
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, YouTube Channel and On-Demand Training for more on how to get started with GitHub.
Last updated July 24, 2020