文檔地址
前言
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 是一個基于分支的輕量級工作流噪猾。它適用于團隊開發(fā)與定期需要發(fā)布的項目租幕。這個文檔解釋了如何使用與為何使用github flow柳沙。
1.Create a branch 創(chuàng)建分支
Create a branch.png
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.
開發(fā)項目的時候,你可能需要創(chuàng)建分支去支持一些新特性,實現(xiàn)一些新想法蜕窿。但是有些分支是可以發(fā)布部署的,有些則沒有準備好。branch就是為了解決這個問題存在的腐泻。在項目里創(chuàng)建了一個新的分支,意味著你可以在新分支里面嘗試新的想法队询。
分支的任何改動派桩,不會影響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鸭津。而且準則只有一個:任何主分支的內(nèi)容都是可部署的。
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.
也正是因為如此肠缨,在主分支以外創(chuàng)建新分支去處理問題與實現(xiàn)新需求是及其重要的逆趋。分支命名記得需要規(guī)范易懂,這樣便于合作開發(fā)晒奕。
2.Add commits 創(chuàng)建分支
Add commits.png
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.
創(chuàng)建了new branch闻书,你就可以在該分支進行內(nèi)容的改動。添加刪除改動文件脑慧,意味著你也要提交改動并且改動需要被添加到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的說明非常重要,因為代碼連同改動和說明都被推送到服務(wù)器(一旦被推到server,git追蹤的改動會被顯示為commits)浪蹂。書寫清晰易懂的說明有助于他人理解你的改動抵栈。
3.Open a Pull Request
Open a Pull Request.png
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 等于創(chuàng)建了一個會話,專門討論你的commits乌逐。因為他們和基礎(chǔ)git倉庫是緊密集成的竭讳,所以任何人都可以了解到他們在合并代碼之后會有哪些改動。
你可以在任何時候開啟pull request:截屏浙踢,新想法绢慢,需要幫助都可以。(所以pull request本質(zhì)上就是一種機制洛波,讓當前的開發(fā)者告訴其余成員胰舆,一個功能已經(jīng)完成。維護者合并之后關(guān)閉這個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提供了一個機制幫助開發(fā)者們在合并代碼到master分支之前充分討論和code review焰扳。
4.Discuss and review your code
Discuss and review your code.png
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你代碼和改動的人會對相關(guān)內(nèi)容有疑問,例如代碼風格不符合標準吨悍,缺少單元測試扫茅。Pull Request 設(shè)計的初衷就是鼓勵這種類型的討論。
Pull Request發(fā)起之后你仍然可以繼續(xù)提交改動到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
圖像.png
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了焰手,就可以進行部署了糟描。發(fā)生任何問題你都可以回滾。
6.Merge
merge.png
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.
現(xiàn)在所有的改動都已經(jīng)被驗證過书妻,可以把代碼合并到主分支船响。一旦合并, 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.
通過把特定關(guān)鍵詞合并到你的Pull Request缤剧,你可以將code和issue關(guān)聯(lián)。當你的Pull Request被合并之后域慷,相關(guān)的issues會被closed荒辕。