git开源_面向开源贡献者的简单Git指南和备忘单

git开源

A go-to git cheat sheet for your open source contributions.

有关您的开源贡献的git备忘单。

If you’re reading this article, you already know that the benefit of open source contribution abounds. You can skip the article and navigate to the end if you’re here for the cheat sheet.

如果您正在阅读本文,您已经知道开源贡献的好处很多。 如果您在此处备忘单,则可以跳过本文并导航到末尾。

The common problem faced by aspiring open source contributors is how to take the first step from fork to pull request. After reading this article, you should be well equipped with all you need to make your first open source pull request.

有抱负的开源贡献者面临的普遍问题是,如何从叉到拉请求迈出第一步。 阅读本文后,您将具备发出第一个开源请求请求所需的一切。

Apart from making the process easier for you, the git workflow defined in this piece also makes your contributions look professional. This is especially useful in case you want to add your open source contributions to your portfolio.

除了使您的过程变得更容易之外,本文中定义的git工作流程还使您的贡献看起来很专业。 如果要将开源贡献添加到投资组合中,这特别有用。

先决条件 (Prerequisites)

This article assumes you already know the steps to take to contribute to open source. If you don’t know, you may want to read this article written by Maryna. This piece also assumes that you’ve already setup Git on your PC. If you haven’t, you may want to check the setting up Git section of this article and do that first.

本文假定您已经知道为开源做出贡献的步骤。 如果您不知道,则可能需要阅读Maryna撰写的这篇文章 。 本文还假设您已经在PC上设置了Git。 如果没有,您可能需要检查本文的Git设置部分,然后首先进行设置。

步骤1:分叉项目 (Step 1: Fork the project)

This is as simple as clicking a button on GitHub. Navigate to the repository of the project you want to contribute to, then click the fork button at the top right corner as illustrated in the picture below.

这就像单击GitHub上的按钮一样简单。 导航到您要参与的项目的资源库,然后单击右上角的fork按钮,如下图所示。

After using the fork button, you’d now have the repository on your GitHub account.

使用fork按钮之后,您现在可以在GitHub帐户上拥有存储库。

步骤2:将项目克隆到本地计算机 (Step 2: Clone the project to your local machine)

This is the simplest part of Git. Navigate to your forked repository (the repository is now one of your GitHub repositories). Follow steps 1 and 2 as shown in the image below to copy the clone address. This address should look like this: https:github.com/suretrust.com/freeCodeCamp.git

这是Git最简单的部分。 导航到您的分叉存储库(该存储库现在是您的GitHub存储库之一)。 如下图所示,按照步骤1和2复制克隆地址。 该地址应如下所示: https: github.com/suretrust.com/freeCodeCamp.git

Then, clone the project by typing git clone <the copied address> into your command terminal as shown below:

然后,通过在您的命令终端中键入git clone <the copied address>来克隆项目,如下所示:

git clone https://github.com/suretrust/freeCodeCamp.git

git clone https://github.com/suretrust/freeCodeCamp.git

步骤3:建立上游 (Step 3: Create upstream)

The upstream is necessary to keep track of the difference between the forked repository that is on your Git account and the original repository. This is most useful if you want to contribute to a popular repository.

上游对于跟踪Git帐户上的分叉存储库与原始存储库之间的差异很有必要。 如果您想为流行的存储库做贡献,这将非常有用。

Some repositories merge pull requests hourly or less, so be safe and assume that the forked repository you have will be behind the original repository.

一些存储库每小时或更短时间合并一次合并请求,因此请确保安全并假定您拥有的分叉存储库将位于原始存储库的后面。

Note that the upstream is in the freeCodeCamp repository and not your forked repository. Follow steps 1 and 2 as shown below to copy the upstream address:

请注意,上游在freeCodeCamp存储库中,而不在您的派生存储库中。 如下所示,按照步骤1和2复制上游地址:

To create a link to the original repository, copy and paste the following command into your terminal:

要创建到原始存储库的链接,请将以下命令复制并粘贴到您的终端中:

git remote add upstream <upstream address>

git remote add upstream <upstream address>

You can use git pull upstream master to confirm if there has been any change at the moment (from when you forked the repository to now).

您可以使用git pull upstream master来确认当前(从分叉存储库到现在)是否有任何更改。

步骤4:建立您要处理的分支 (Step 4: Create the branch you want to work on)

It is nice to create a new branch whenever you want to contribute. This illustrates that the branch is only for that contribution you are about to make. It could be as small as fixing a typo or as large as implementing a new feature. Either way, it’s good practice to create a branch.

每当您想贡献时,最好创建一个新分支。 这说明分支仅用于您将要做出的贡献。 它的大小可以像修正错字一样小,也可以像实现新功能一样大。 无论哪种方式,创建分支都是一种好习惯。

Another important part of the branch creation is naming. It is pleasing to use a name that a stranger who knows nothing about the repository can easily understand. If you want to add a login feature, for example, you could create a branch called add-login-feature or login-feature.

分支创建的另一个重要部分是命名。 使用一个对存储库一无所知的陌生人可以轻松理解的名字是令人愉快的。 例如,如果要添加登录功能,则可以创建一个名为add-login-featurelogin-feature的分支。

To create a branch type the following command into your terminal:

要创建分支,请在终端中输入以下命令:

git checkout -b <your branch name>

git checkout -b <your branch name>

This command will create the branch and navigate into it. If your branch name is login-feature, then you can use the following command:

此命令将创建分支并导航到该分支。 如果您的分支名称为login-feature,则可以使用以下命令:

git checkout -b login-feature

git checkout -b login-feature

Then add your contributions. After adding your contribution, move on to Step 5.

然后添加您的贡献。 添加贡献后,继续执行步骤5。

步骤5:Git添加并提交您的贡献 (Step 5: Git add and commit your contributions)

This is quite simple as well. Stage and commit your changes by typing the following into your terminal.

这也很简单。 通过在终端中输入以下内容来暂存并提交更改。

git add .

git add .

git commit -m 'Commit message'

git commit -m 'Commit message'

Now, you have the changes staged and committed. What next?

现在,您已上演并提交了更改。 接下来是什么?

步骤6:从上游拉到分支 (Step 6: Pull from upstream to the branch)

As I explained in step 4, this step is to merge any difference in the upstream into the branch so as to prevent conflicts.

正如我在步骤4中解释的那样,此步骤是将上游的任何差异合并到分支中,以防止发生冲突。

git pull upstream <branch name>

git pull upstream <branch name>

This merges the upstream changes into your current branch.

这会将上游更改合并到您的当前分支中。

第7步:推送到您正在处理的分支 (Step 7: Push to the branch you’re working on)

Now, you are almost there. Push your changes to the branch you are working on as shown below:

现在,您快到了。 将更改推送到您正在处理的分支,如下所示:

git push origin <branch-name>

git push origin <branch-name>

步骤8:打开拉取请求 (Step 8: Open a pull request)

This is the final step for any open source contribution, you are simply saying ‘I have made some changes, would you mind adding it to the project?’.

这是任何开源贡献的最后一步,您只是在说“我做了一些更改,您介意将其添加到项目中吗?”。

You open a pull request and if the repository owner or members like what they see, they’ll merge it. Otherwise, they could make changes then merge or request for changes.

打开拉取请求,如果存储库所有者或成员喜欢他们所看到的内容,则他们将合并它。 否则,他们可以进行更改,然后合并或请求更改。

To open a pull request, navigate to the forked repository as shown below. You’ll see your last push branch ‘login-feature’, then click on ‘compare and pull request’.

要打开拉取请求,请导航至如下所示的分叉存储库。 您将看到最后一个推送分支'login-feature' ,然后单击'compare and pull request'

Explain clearly, the changes you made, then open a pull request as shown below:

清楚地说明您所做的更改,然后打开一个拉取请求,如下所示:

And that’s it. :) You can now go ahead and contribute like a PRO!

就是这样。 :)您现在就可以像专业人士一样做出贡献!

适用于开源贡献者的Git备忘单 (Git cheat sheet for open source contributors)

Peace out and happy contributing!

和平了,乐于奉献!

翻译自: https://www.freecodecamp.org/news/a-simple-git-guide-and-cheat-sheet-for-open-source-contributors/

git开源

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值