文档地址
前言
GitHub Flow is a lightweight, branch-based workflow that supports teams and projects where deployments are made regularly. This guide explains how and why GitHub Flow works.
GitHub Flow 是一个基于分支的轻量级工作流。它适用于团队开发与定期需要发布的项目。这个文档解释了如何使用与为何使用github flow。
1.Create a branch 创建分支
When you're working on a project, you're going to have a bunch of different features or ideas in progress at any given time – some of which are ready to go, and others which are not. Branching exists to help you manage this workflow.
When you create a branch in your project, you're creating an environment where you can try out new ideas. Changes you make on a branch don't affect the master branch, so you're free to experiment and commit changes, safe in the knowledge that your branch won't be merged until it's ready to be reviewed by someone you're collaborating with.
开发项目的时候,你可能需要创建分支去支持一些新特性,实现一些新想法。但是有些分支是可以发布部署的,有些则没有准备好。branch就是为了解决这个问题存在的。在项目里创建了一个新的分支,意味着你可以在新分支里面尝试新的想法。
分支的任何改动,不会影响master主分支。所以你可以尽情的改动,尝试并且comm你的改动。但是如果你想merge分支,你得确认你的代码可以被合作者们review.
ProTip
Branching is a core concept in Git, and the entire GitHub flow is based upon it. There's only one rule: anything in the master branch is always deployable.
branch-分支是git中的核心概念。整个Github flow 都基于branch。而且准则只有一个:任何主分支的内容都是可部署的。
Because of this, it's extremely important that your new branch is created off of master when working on a feature or a fix. Your branch name should be descriptive (e.g., refactor-authentication, user-content-cache-key, make-retina-avatars), so that others can see what is being worked on.
也正是因为如此,在主分支以外创建新分支去处理问题与实现新需求是及其重要的。分支命名记得需要规范易懂,这样便于合作开发。
2.Add commits 创建分支
Once your branch has been created, it's time to start making changes. Whenever you add, edit, or delete a file, you're making a commit, and adding them to your branch. This process of adding commits keeps track of your progress as you work on a feature branch.
Commits also create a transparent history of your work that others can follow to understand what you've done and why. Each commit has an associated commit message, which is a description explaining why a particular change was made. Furthermore, each commit is considered a separate unit of change. This lets you roll back changes if a bug is found, or if you decide to head in a different direction.
创建了new branch,你就可以在该分支进行内容的改动。添加删除改动文件,意味着你也要提交改动并且改动需要被添加到branch中。
提交都是有完整详细的记录,任何资源的修改都有。它的意义在于告诉别人你做了什么操作,以及为什么。
每个commit对有对应的详细说明。说明需要解释你做了什么改动,为什么改动。而且,每个commit都可以被视为change的一个小组成单元。这有助于你回溯来改BUG。
ProTip
Commit messages are important, especially since Git tracks your changes and then displays them as commits once they're pushed to the server. By writing clear commit messages, you can make it easier for other people to follow along and provide feedback.
commit的说明非常重要,因为代码连同改动和说明都被推送到服务器(一旦被推到server,git追踪的改动会被显示为commits)。书写清晰易懂的说明有助于他人理解你的改动。
3.Open a Pull Request
Pull Requests initiate discussion about your commits. Because they're tightly integrated with the underlying Git repository, anyone can see exactly what changes would be merged if they accept your request.
You can open a Pull Request at any point during the development process: when you have little or no code but want to share some screenshots or general ideas, when you're stuck and need help or advice, or when you're ready for someone to review your work. 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 ten time zones away.
Pull requests 等于创建了一个会话,专门讨论你的commits。因为他们和基础git仓库是紧密集成的,所以任何人都可以了解到他们在合并代码之后会有哪些改动。
你可以在任何时候开启pull request:截屏,新想法,需要帮助都可以。(所以pull request本质上就是一种机制,让当前的开发者告诉其余成员,一个功能已经完成。维护者合并之后关闭这个PR。)
ProTip
Pull Requests are useful for contributing to open source projects and for managing changes to shared repositories. If you're using a Fork & Pull Model, Pull Requests provide a way to notify project maintainers about the changes you'd like them to consider. If you're using a Shared Repository Model, Pull Requests help start code review and conversation about proposed changes before they're merged into the master branch.
Pull Requests在向开源项目贡献代码,管理共享项目的改动的时候都很管用。Pull Requests提供了一个机制帮助开发者们在合并代码到master分支之前充分讨论和code review。
4.Discuss and review your code
Once a Pull Request has been opened, the person or team reviewing your changes may have questions or comments. Perhaps the coding style doesn't match project guidelines, the change is missing unit tests, or maybe everything looks great and props are in order. Pull Requests are designed to encourage and capture this type of conversation.
You can also continue to push to your branch in light of discussion and feedback about your commits. If someone comments that you forgot to do something or if there is a bug in the code, you can fix it in your branch and push up the change. GitHub will show your new commits and any additional feedback you may receive in the unified Pull Request view.
Pull Request 开启之后,review你代码和改动的人会对相关内容有疑问,例如代码风格不符合标准,缺少单元测试。Pull Request 设计的初衷就是鼓励这种类型的讨论。
Pull Request发起之后你仍然可以继续提交改动到branch。Github会显示你最新的commits。
ProTip
Pull Request comments are written in Markdown, so you can embed images and emoji, use pre-formatted text blocks, and other lightweight formatting.
Pull Request使用的是markdown,所以你可以放emoji和images等等等等。
5.Deploy
With GitHub, you can deploy from a branch for final testing in production before merging to master.
Once your pull request has been reviewed and the branch passes your tests, you can deploy your changes to verify them in production. If your branch causes issues, you can roll it back by deploying the existing master into production.
在github上你可以在branch合并到master分支上之前,进行测试等配置。一切都OK了,就可以进行部署了。发生任何问题你都可以回滚。
6.Merge
Now that your changes have been verified in production, it is time to merge your code into the master branch.
Once merged, Pull Requests preserve a record of the historical changes to your code. Because they're searchable, they let anyone go back in time to understand why and how a decision was made.
现在所有的改动都已经被验证过,可以把代码合并到主分支。一旦合并, Pull Requests会保存你更改的历史记录。因为他们是可查询的。这样对任何人来说,记录都是可回溯的。
ProTip
By incorporating certain keywords into the text of your Pull Request, you can associate issues with code. When your Pull Request is merged, the related issues are also closed. For example, entering the phrase Closes #32 would close issue number 32 in the repository. For more information, check out our help article.
通过把特定关键词合并到你的Pull Request,你可以将code和issue关联。当你的Pull Request被合并之后,相关的issues会被closed。