github上拉取项目
When we love someone’s repository and would like to have it in our GitHub account, we fork it so that we can work with it separately.
当我们喜欢某人的存储库并希望将其存储在我们的GitHub帐户中时,我们会对其进行分叉,以便我们可以单独使用它。
When we fork a repository, we get an instance of that entire repository with its whole history. After forking, we can do whatever we want to do without affecting the original version.
派生存储库时,我们将获得整个存储库的实例及其全部历史记录。 分叉之后,我们可以做任何想做的事情而不会影响原始版本。
Pull requests are the way we contribute to group projects or open source projects.
拉取请求是我们为小组项目或开源项目做出贡献的方式。
For instance, a user Harry forks a repository of ThanoshanMV and makes changes to that repository. Now Harry can make a pull request to ThanoshanMV, but it’s up to ThanoshanMV to accept or decline it. It’s like saying, “ThanoshanMV, would you please pull my changes?”
例如,用户Harry派生了ThanoshanMV存储库,并对该存储库进行了更改。 现在,Harry可以向ThanoshanMV发出拉动请求,但这取决于ThanoshanMV接受还是拒绝。 就像在说:“ ThanoshanMV,请您拉我的零钱吗?”
Not only can we contribute to an open source project with code, but we can also contribute in many other ways. Some of these ways are described below.
我们不仅可以使用代码为开源项目做出贡献,而且还可以通过许多其他方式做出贡献。 这些方法中的一些描述如下。
As 99xtechnology IT firm’s hacktitude starting guide says, we can contribute to an open source project in the following ways:
正如99xtechnology IT公司的hacktitude入门指南所说,我们可以通过以下方式为开源项目做出贡献:
If you’re not very familiar with Git & GitHub, please go review The beginner’s guide to Git & GitHub.
如果您对Git和GitHub不太熟悉,请查看Git和GitHub入门指南 。
Fork the repository by clicking the fork button on the top of the page. This will create an instance of that entire repository in your account.
通过单击页面顶部的fork按钮来分叉存储库。 这将在您的帐户中创建整个存储库的实例。
Once the repository is in your account, clone it to your machine to work with it locally.
将存储库放入您的帐户后,将其克隆到您的计算机上以在本地使用它。
To clone, click on the clone button and copy the link.
要克隆,请单击“克隆”按钮并复制链接。
Open the terminal and run the following command. It will clone the repository locally.
打开终端并运行以下命令。 它将在本地克隆存储库。
$ git clone [HTTPS ADDRESS]
Now we have set up a copy of the master branch from the main online project repository.
现在,我们已经从主要的在线项目存储库中建立了master分支的副本。
We need to go to that cloned directory by running this command:
我们需要通过运行以下命令转到该克隆目录:
$ cd [NAME OF REPOSITORY]
It’s good practice to create a new branch when working with repositories, whether it’s a small project or contributing to a group's work.
无论是小型项目还是对小组的工作有所帮助,在存储库中创建一个新分支都是一个好习惯。
Branch name should be short and it should reflect the work we’re doing.
分支名称应该简短,并且应该反映我们正在做的工作。
Now create a branch using the git checkout
command:
现在使用git checkout
命令创建一个分支:
$ git checkout -b [Branch Name]
Make essential changes to the project and save it.
对项目进行必要的更改并保存。
Then execute git status
, and you’ll see the changes.
然后执行git status
,您将看到更改。
Add those changes to the branch you just created using the git add
command:
将这些更改添加到使用git add
命令刚创建的分支中:
$ git add .
Now commit those changes using the git commit
command:
现在,使用git commit
命令提交这些更改:
$ git commit -m "Adding an article to week 02 of articles of the week"
In order to push the changes to GitHub, we need to identify the remote’s name.
为了将更改推送到GitHub,我们需要确定远程服务器的名称。
$ git remote
For this repository the remote’s name is “origin”.
对于此存储库,远程名称为“ origin”。
After identifying the remote’s name we can safely push those changes to GitHub.
确定了远程服务器的名称后,我们可以安全地将这些更改推送到GitHub。
git push origin [Branch Name]
Go to your repository on GitHub and you’ll see a button “Compare & pull request” and click it.
转到GitHub上的存储库,您将看到一个“比较并提取请求”按钮,然后单击它。
Please provide necessary details on what you’ve done (You can reference issues using “#”). Now submit the pull request.
请提供您所做工作的必要详细信息(您可以使用“#”引用问题)。 现在提交拉取请求。
Congratulations! You've made your first pull request.
恭喜你! 您已经提出了第一个请求请求。
If your pull request is accepted you’ll receive an email.
如果您的请求请求被接受,您将收到一封电子邮件。
Before submitting any pull requests to the original repository you have to sync your repository to the original one.
在将任何请求请求提交到原始存储库之前,您必须将存储库同步到原始存储库。
Even if you are not going to submit a pull request to the original repository, it’s better to sync with the original repository as some additional features and bug fixes may have been done since you forked the original repository.
即使您不打算向原始存储库提交拉取请求,也最好与原始存储库同步,因为自从您创建原始存储库以来,可能已经完成了一些其他功能和错误修复。
Follow these steps to update/sync those changes to your master branch:
请按照以下步骤将这些更改更新/同步到您的master分支:
$ git branch
It’ll list all branches and indicates the current or active branch in green.
它会列出所有分支,并以绿色指示当前或活动分支。
2. Switch to the master branch.
2.切换到master分支。
$ git checkout master
3. Add the original repository as an upstream repository.
3.将原始存储库添加为上游存储库。
In order to pull the changes from the original repository into your forked version, you need to add the original Git repository as an upstream repository.
为了将更改从原始存储库提取到派生版本中,您需要将原始Git存储库添加为上游存储库。
$ git remote add upstream [HTTPS]
Here, [HTTPS] is the URL that you have to copy from the owner’s repository.
在此,[HTTPS]是您必须从所有者的存储库中复制的URL。
4. Fetch the repository.
4.提取存储库。
Fetch all of the changes from the original repository. Commits to the original repository will be stored in a local branch called upstream/master.
从原始存储库中获取所有更改。 提交到原始存储库的内容将存储在称为上游/主服务器的本地分支中。
$ git fetch upstream
5. Merge it.
5.合并。
Merge the changes from the upstream/master into your local master branch. This will bring your fork’s master branch into sync with the upstream repository without losing your local changes.
将更改从上游/主服务器合并到本地主服务器分支。 这将使fork的master分支与上游存储库同步,而不会丢失本地更改。
$ git merge upstream/master
6. Push changes to GitHub
6.将更改推送到GitHub
At this point your local branch is synced to the original repository’s master branch. If you want to update the GitHub repository, you need to push your changes.
此时,您的本地分支已同步到原始存储库的master分支。 如果要更新GitHub存储库,则需要推送更改。
$ git push origin master
NOTE: After syncing your forked master branch you can remove that remote if you want to. But you’ll need to update/sync your repository in future too, so it's best practice to keep it.
注意:同步分支的master分支后,您可以根据需要删除该遥控器。 但是将来您也需要更新/同步存储库,因此最好的做法是保留它。
$ git remote rm [Remote Name]
Branches are created for a special purpose. Once that purpose is accomplished, those branches aren’t necessary, so you can delete them.
创建分支是出于特殊目的。 一旦达到该目的,就不需要那些分支,因此可以将其删除。
$ git branch -d [Branch Name]
You can delete the version of it on GitHub, too.
您也可以在GitHub上删除它的版本。
git push origin --delete [Branch Name]
GitHub is a powerful tool to control version history. Everyone can contribute to open source projects by making pull requests. Contributions aren’t always code – there are other ways to contribute, too.
GitHub是控制版本历史记录的强大工具。 每个人都可以通过发出请求请求为开源项目做出贡献。 贡献并不总是编写代码–还有其他贡献方式。
Finally, I have to tell you that you shouldn't worry if your pull requests are rejected. Maintainers spend a lot time improving their projects, and they know a lot more about their projects than we do. So don't worry if your request isn't merged.
最后,我必须告诉您,如果您的请求请求被拒绝,您不必担心。 维护人员花费大量时间来改善他们的项目,并且他们比我们更了解他们的项目。 因此,请不要担心您的请求没有合并。
Stay strong, stay positive, and never give up.
保持坚强,保持积极,永不放弃。
― Roy T. Bennett, The Light in the Heart
―罗伊·T·贝内特(Roy T.Bennett), 《心中的光》
This article was originally posted on Medium.
本文最初发布在Medium上 。
You can contact and connect with me on Twitter.
您可以在Twitter上与我联系并建立联系。
Keep contributing to the open source world!
继续为开源世界做贡献!
翻译自: https://www.freecodecamp.org/news/how-to-make-your-first-pull-request-on-github-3/
github上拉取项目