Learn Git and GitHub without any code!
Using the Hello World guide, you’ll start a branch, write comments, and open a pull request.
https://guides.github.com/activities/hello-world/
Hello World
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开始吧!
你将学习如何:
创建和使用存储库
启动和管理新分支
对文件进行更改并将其作为提交推送到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.
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.
什么是Github?
github是一个用于版本控制和协作的代码托管平台。它让你和其他人在任何地方的项目上一起工作。
本教程将向您介绍GitHub的基本功能,如存储库、分支、提交和拉取请求。您将创建自己的hello world存储库,并学习github的pull-request工作流,这是一种创建和审查代码的流行方法。
无需编码
要完成本教程,您需要github.com帐户和Internet访问。您不需要知道如何编写代码、使用命令行或安装git(版本控制软件github是基于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使您可以在创建新存储库的同时轻松添加一个存储库。它还提供其他常见选项,如许可证文件。
hello world存储库可以是一个存储想法、资源,甚至与他人共享和讨论内容的地方。
Great repository names are short and memorable. Need inspiration? How about improved-octo-memory?
伟大的存储库名称是简短和难忘的。需要灵感吗?提高octo的记忆力怎么样?
Description (optional)
说明(可选)
Anyone can see this repository. You choose who can commit.
任何人都可以看到这个存储库。你选择谁可以承诺。
You choose who can see and commit to this repository.
您可以选择谁可以查看并提交到此存储库。
Skip this step if you’re importing an existing repository.
如果要导入现有存储库,请跳过此步骤。
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
步骤2。创建分支
分支是一次处理不同版本存储库的方法。
默认情况下,存储库有一个名为master的分支,该分支被视为最终分支。在将分支提交给master之前,我们使用分支进行实验和编辑。
当您在主分支上创建分支时,您正在按主分支在该时间点上的状态创建主分支的副本或快照。如果其他人在您处理分支时对主分支进行了更改,您可以将这些更新拉入。
此图显示:
主枝
一个名为feature的新分支(因为我们正在对这个分支执行“feature work”)
该功能在融入主功能之前所经历的旅程
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.
你保存过不同版本的文件吗?类似于:
TXT
story-joe-edit.txt文件
story-joe-edit-reviewed.txt文件
分支在github存储库中实现类似的目标。
在github,我们的开发人员、作者和设计师使用分支来保持bug修复和功能工作与我们的主(生产)分支分离。当变化准备好时,他们将分支合并为master。
创建新分支
转到新的存储库hello world。
单击文件列表顶部显示branch:master的下拉列表。
在“新建分支”文本框中键入分支名称“自述编辑”。
选择蓝色的创建分支框或按键盘上的“回车”键。
Switch branches/tags
切换分支/标记
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编辑。它们看起来一模一样,但不会太久!下一步我们将把我们的更改添加到新的分支。
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.
步骤3。进行和提交更改
好极了!现在,您进入了readme edits分支的代码视图,它是master的副本。让我们做些编辑。
在github上,保存的更改称为提交。每个提交都有一个关联的提交消息,这是一个说明,解释为什么进行了特定更改。提交消息捕获更改的历史记录,以便其他贡献者能够理解您所做的操作以及原因。
进行和提交更改
单击readme.md文件。
单击文件视图右上角的铅笔图标进行编辑。
在编辑器中,写一点关于你自己的东西。
编写一条描述更改的提交消息。
单击“提交更改”按钮。
Commit directly to the readme-edits branch.
直接提交到自述编辑分支。
Create a new branch for this commit and start a pull request. Learn more about pull requests.
为此提交创建一个新分支并启动一个拉取请求。了解有关拉取请求的更多信息。
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
步骤4。打开拉取请求
尼斯编辑!现在您已经更改了master的分支,可以打开一个pull请求。
拉取请求是github上协作的核心。当您打开一个请求时,您提出了您的更改,并请求有人检查和拉入您的贡献并将其合并到他们的分支中。拉取请求显示来自两个分支的内容的差异。更改、添加和减法显示为绿色和红色。
一旦提交,就可以打开请求并开始讨论,甚至在代码完成之前。
通过在pull请求消息中使用github的@notice系统,您可以请求特定人员或团队的反馈,无论他们是在大厅下面还是10个时区之外。
您甚至可以在自己的存储库中打开pull请求并自己合并它们。在处理更大的项目之前,这是学习github流的好方法。
打开请求更改自述文件
点击图片查看更大版本
Click the Pull Request tab, then from the Pull Request page, click the green New pull request button.
In the Example Comparisonsbox, select the branch you made, readme-edits
, to compare with master
(the original).
单击“拉取请求”选项卡,然后在“拉取请求”页面中,单击绿色的“新建拉取请求”按钮。
在“示例比较”框中,选择要与主控形状(原始形状)进行比较的分支“自述编辑”。
Compare changes
Compare changes across branches, commits, tags, and more below. If you need to, you can also compare across forks.
比较更改
比较分支、提交、标记和下面更多内容之间的更改。如果你需要的话,你也可以用叉子来比较。
Choose different branches or forks above to discuss and review changes.
选择以上不同的分支或分支来讨论和评审更改。
Compare and review just about anything
Branches, tags, commit ranges, and time ranges. In the same repository and across forks.
比较和回顾任何事情
分支、标记、提交范围和时间范围。在同一个存储库中,跨越叉子。
- EXAMPLE COMPARISONS
示例比较
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.
当您确信这些是要提交的更改时,请单击绿色的“创建请求”按钮。
Able to merge. These branches can be automatically merged.
能够合并。这些分支可以自动合并。
Discuss and review the changes in this comparison with others.
与其他人讨论并回顾此比较中的更改。
Verified
已验证
Showing 1 changed file with 3 additions and 0 deletions.
显示1个已更改的文件,包括3个添加和0个删除。
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.
完成邮件后,单击“创建拉取请求”!
提示:您可以使用emoji并将图像和gif拖放到评论和请求中
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.
步骤5。合并拉取请求
在最后一步中,是时候将您的更改合并到一起了——将您的自述编辑分支合并到主分支中。
单击绿色的合并请求按钮将更改合并到主控形状。
单击“确认合并”。
继续并删除分支,因为它的更改已经合并,紫色框中有delete branch按钮。
Add more commits by pushing to the readme-edits
branch on wlinjie/hello-world.
通过在wlinjie/hello world上的readme edits分支添加更多提交。
This branch has no conflicts with the base branch
Merging can be performed automatically.
此分支与基分支没有冲突
合并可以自动执行。
You can also open this in GitHub Desktop or view command line instructions
您也可以在github桌面或查看命令行说明中打开它
Pull request successfully merged and closed
You’re all set—the readme-edits branch can be safely deleted.
成功合并并关闭拉取请求
您都设置了“自述编辑”分支可以安全删除。
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 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.
看看你的github档案,你会看到你的新贡献广场!
要了解pull请求的强大功能,我们建议阅读github流指南。您还可以访问github explore并参与一个开源项目。
Tip: Check out our other Guides, YouTube Channel and On-Demand Training for more on how to get started with GitHub.
提示:查看我们的其他指南、youtube频道和点播培训,了解更多关于如何开始使用github的信息。
原文地址:https://www.cnblogs.com/wanglinjie/p/11605096.html