原文链接:点击打开链接
阅读官方文档一方面是最权威的讲解,另一方面又能提高你的英语阅读能力,同时让你有一个进步的满足感,英语基础不好的同学可以结合翻译阅读学习,或者直接观看翻译(下方为翻译)
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
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).
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 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.
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
. - 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 master
which is considered to be the definitive branch. We use branches to experiment and make edits before committing them to 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.
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 intomaster
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
.
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.
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.
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.
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.
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
.
Step 4. Open a Pull Request
Nice edits! Now that you have changes in a branch off of master
, you can open a 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 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.
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.
Open a Pull Request for changes to the README
Click on the image for a larger version
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 master
branch.
- Click the green Merge pull request button to merge the changes into
master
. - Click Confirm merge.
- Go ahead and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.
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
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.
以下为翻译内容:
Hello,World!
简介
GitHub是一个通过Git进行版本控制的软件源代码托管服务,由GitHub公司(曾称Logical Awesome)的开发者Chris Wanstrath、PJ Hyett和Tom Preston-Werner使用Ruby on Rails编写而成。
GitHub同时提供付费账户和免费账户。这两种账户都可以创建公开的代码仓库,但是付费账户还可以创建私有的代码仓库。根据在2009年的Git用户调查,GitHub是最流行的Git访问站点.
除了允许个人和组织创建和访问保管中的代码以外,它也提供了一些方便社会化共同软件开发的功能,即一般人口中的社区功能,包括允许用户追踪其他用户、组织、软件库的动态,对软件代码的改动和bug提出评论等。GitHub也提供了图表功能,用于概观显示开发者们怎样在代码库上工作以及软件的开发活跃程度。
截止到2015年,GitHub已经有超过九百万注册用户和2110万代码库。
事实上已经成为了世界上最大的代码存放网站和开源社区
更多:维基百科
开始使用GitHub
本文是我对于官方文档:Hello World 的翻译。
Hello World 项目是计算机编程中一个历史悠久的传统。 这是一个在你开始学习新东西时候的简单练习。 让我们开始使用GitHub吧!
您将学会:
- 创建和使用存储库(repository);
- 启动和管理新分支(branch);
- 对文件进行更改并将其推送提交(commit)到GitHub ;
- 打开并合并一个Pull请求。
什么是GitHub?
GitHub是用于版本控制和协作的代码托管平台。 它可以让你和其他人在任何地方协同工作同一个项目。
本教程教你GitHub的要素,如仓库(repositories),分支(branches),提交(commits) 和Pull请求。 您将创建自己的Hello World 项目存储库,并学习GitHub的Pull Request工作流程,这是一种流行的创建和审查代码的方法。
无需编码
要完成本教程,您需要一个GitHub帐户和可以连接的Internet网络。 您不需要知道如何编码,使用命令行,或安装Git(GitHub的版本控制软件被建立于此)。
提示:在单独的浏览器窗口(或选项卡)中打开此指南,以便在完成教程中的步骤时可以看到它。
步骤1.创建存储库(Repository)
存储库(repository)通常用于组织单个项目。 存储库可以包含文件夹和文件,图像,视频,电子表格和数据集 - 即项目需要的任何内容。 我们建议您包括一个README文件,或包含有关您的项目信息的文件。 GitHub使得在创建新存储库的同时添加一个README文件很容易实现。 它还提供其他常见选项,如许可证文件。
你的 hello-world
存储库 可以是一个你存储想法,资源,甚至与他人分享和讨论内容的地方。
创建新存储库(Repository)
- 在右上角,在您的头像或识别码旁边,单击 + 然后选择“Create new...”。
- 命名您的存储库名称为
hello-world
。 - 写一个简短的描述(description)。
- 勾选 Initialize this repository with a README(使用README初始化此存储库。)
点击 Create repository(创建存储库)。
步骤2.创建分支(Branch)
分支(Branching) 是同时在同一个存储库中创建不同版本的方式。
默认情况下,你的仓库有一个名称为master
的分支,它被认为是最终分支。 我们使用分支进行实验和编辑,然后将分支提交到master
。
当您在主master
分支上创建分支时,您就创建了主master
节点在该时间点的副本或快照。 如果有人在您在分支上工作时对主master
分支进行了更改,你就可以提取这些更新。
此图显示:
- 主分支 The
master
branch - 一个新的分支称之为 映像(
feature
)(因为我们在这个分支上做“映像工作”) - 在映像(
feature
)被合并到主master
分支上的旅程
你曾经保存过一个文件的不同版本吗? 就像是:
- story.txt
- story-joe-edit.txt
- story-joe-edit-reviewed.txt
分支(Branch) 在GitHub存储库中实现类似的目标。
在GitHub上,我们的开发人员,作家和设计师使用分支来保持错误的修复和功能工作在独立于我们的主(产品)分支上。 当更改准备就绪时,它们将其分支合并到主master()节点上。
创建一个新的分支
- 进入您的新存储库
hello-world
。 - 单击文件列表顶部叫做 branch:master 的下拉列表。
- 在新分支文本框中键入分支名称readme-edits。
- 选择蓝色的 Create branch 框或按键盘上的“Enter”。
现在你有两个分支,master
和readme-edits
。 他们看起来完全一样,但不长久! 接下来,我们将把更改添加到新分支。
步骤3.制作并提交更改
哇哦! 现在,你在readme-edits
分支的代码视图上,这是master
的副本。 让我们做一些编辑。
在GitHub上,保存的更改称为提交(commit)。 每个提交都有一个相关的提交消息,这是一个描述为什么进行特定更改的描述。 提交消息会捕获您更改的历史记录,因此其他参与者可以了解您的操作以及原因。
制作并提交更改
- 单击
README.md
文件。 - 在文件视图的右上角单击✎铅笔图标编辑。
- 在编辑器中,写一点关于你自己的东西。
- 编写提交消息来描述您的更改的内容。
- 单击 Commit changes 提交更改按钮。
这些更改将只发生在readme-edits
分支上的README文件,因此现在此分支包含的内容与master
不同。
步骤4.开启拉取请求(Pull Request)
干得漂亮! 现在,您在master
的分支中有更改,您可以开启拉取请求了。
Pull Request 请求是GitHub协作的核心。 当您开启拉取请求时,您就会提出您的更改和请求,并要求某人审核并提交您的贡献,并将其合并到他们的分支中。 拉取请求会显示来自两个分支的内容的差异或差异。 更改,添加和减少以绿色和红色显示。
一旦提交(commit)以后,您就可以开启一个拉取请求(Pull Request)并,在代码完成之前展开讨论。
通过在您的请求消息中使用GitHub的@提醒系统,您可以请求特定人员或团队的反馈,无论他们是在大厅还是在10个时区以外。
您甚至可以在您自己的存储库中开启拉取请求并自行合并它们。 这是一个在更大的项目之前学习GitHub流的伟大的方式。
开启一个对README的更改的Pull Requset
点击图片获得更大的版本
当你完成填写以上信息后,点击 Create pull request。
步骤5.合并(merge)您的请求
在这最后一步,是时候把你的更改放在一起了 - 合并你的readme-edits
分支到master
分支。
- 单击绿色Merge pull request按钮将更改合并到
master
中。
- 单击确认合并(Confirm merge)。
- 继续并删除分支,因为它的更改已被合并,删除分支(Delete branch)按钮在紫色框中。
恭喜
通过完成本教程,您已经学会了创建一个项目,并在GitHub上发出pull request了