GitHub入门之Hello World project

项目介绍

Hello World项目是计算机编程领域的悠久历史。这是一个简单的练习,可以让您从中学到新知识开始。让我们开始使用GitHub!

功能介绍

  1. 创建和使用存储库
    Create and use a repository
  2. 启动和管理新分支
    Start and manage a new branch
  3. 更改文件并将其作为提交推送到
    GitHub Make changes to a file and push them to GitHub as commits
  4. 打开并合并拉取请求
    Open and merge a pull request

什么是GitHub?

GitHub是用于版本控制和协作的代码托管平台。它使您和其他人可以在任何地方共同处理项目。

创建Hello World project步骤

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.

存储库通常用于组织单个项目。存储库可以包含文件夹和文件,图像,视频,电子表格和数据集-项目需要的任何内容。我们建议包括自述文件或包含有关您的项目信息的文件。使用GitHub可以轻松地在创建新存储库的同时添加一个。它还提供了其他常用选项,例如许可证文件。
Hello World存储库可以是您存储思想,资源,甚至与他人共享和讨论事物的地方。

  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.
  5. Click Create repository.
    GitHub入门之Hello World project
    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.

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:

1)The main 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 main
GitHub入门之Hello World projectHave 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中。

  1. Go to your new repository hello-world.
  2. Click the drop down at the top of the file list that says branch: main.
  3. Type a branch name, readme-edits, into the new branch text box.
  4. Select the blue Create branch box or hit “Enter” on your keyboard.
    GitHub入门之Hello World project
    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.

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.

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分支的代码视图中,该分支是main的副本。让我们进行一些编辑。

在GitHub上,保存的更改称为提交。每个提交都有一个关联的提交消息,该消息是说明为什么进行特定更改的说明。提交消息记录了更改的历史记录,因此其他贡献者可以了解您所做的事情以及原因。

  1. Click the README.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.
    GitHub入门之Hello World project
    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.

4. Open a Pull Request

Now that you have changes in a branch off of main, 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.
现在您已经在main分支中进行了更改,现在可以打开拉取请求。

拉取请求是GitHub上协作的核心。当您打开请求请求时,您是在提出更改,并要求某人查看并提取您的贡献并将其合并到其分支中。拉取请求显示两个分支中内容的差异或差异。更改,加法和减法以绿色和红色显示。

提交后,即使在代码完成之前,也可以打开请求请求并开始讨论。

通过在请求请求消息中使用GitHub的@mention系统,您可以要求特定人员或团队提供反馈,无论他们是在大厅还是10个时区之外

步骤参考:
https://guides.github.com/activities/hello-world/

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.

  1. Click the green Merge pull request button to merge the changes into main.
  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.
    GitHub入门之Hello World project

参考文献

  1. https://guides.github.com/activities/hello-world/