譯自:《GitHub Guides》
時(shí)間:2018-2-27
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 項(xiàng)目在計(jì)算機(jī)編程里有著悠久傳統(tǒng)。當(dāng)你開(kāi)始學(xué)習(xí)新的東西但绕,這往往作為一個(gè)簡(jiǎn)單的練習(xí)可以讓你快速了解。讓我們?cè)贕itHub中開(kāi)始吧!
你將學(xué)會(huì)如何:
1.創(chuàng)建和使用存儲(chǔ)庫(kù)
2.啟動(dòng)和管理一個(gè)新分支
3.更改一個(gè)文件,把他們放入GitHub作為一個(gè)歷史根據(jù)
4.打開(kāi)并合并一個(gè)上傳的請(qǐng)求
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.
什么是Github始苇?
是一個(gè)用作版本控制和協(xié)作溝通的代碼托管平臺(tái)营搅。它讓你與別人無(wú)論何地都可以一起做項(xiàng)目。本教程教你GitHub的要領(lǐng)比如:倉(cāng)庫(kù)(存放處)辫诅,分支機(jī)構(gòu),提交涧狮,獲取請(qǐng)求炕矮。你將創(chuàng)建一個(gè)屬于你自己的“Hello World”的存放處么夫,學(xué)習(xí)Github的獲取請(qǐng)求的工作流——一種流行的方式來(lái)創(chuàng)建和評(píng)審代碼。
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.
不強(qiáng)制你編碼
要完成本教程肤视,您需要一個(gè)github.com帳戶档痪,互聯(lián)網(wǎng)可接入。你不需要知道如何編寫(xiě)代碼邢滑,如何使用命令行腐螟,或安裝Git(版本控制軟件是一個(gè)內(nèi)置的GitHub在線)。
提示:在一個(gè)單獨(dú)的瀏覽器窗口(或標(biāo)簽)打開(kāi)本指南困后,這樣你在完成教程里的步驟時(shí)也能看到它乐纸。
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.創(chuàng)建一個(gè)存儲(chǔ)庫(kù)(版本庫(kù)、倉(cāng)庫(kù))
存儲(chǔ)庫(kù)通常用于組織單個(gè)項(xiàng)目摇予。存儲(chǔ)庫(kù)可以包含文件夾和文件汽绢、圖像、視頻侧戴、電子表格和數(shù)據(jù)集——任何你的項(xiàng)目所需要的宁昭。我們建議包含一個(gè)自述文件或一個(gè)包含關(guān)于您的項(xiàng)目信息的文件。GitHub可以很容易地添加一個(gè)同時(shí)您創(chuàng)建新的庫(kù)酗宋。它還提供其他常見(jiàn)選項(xiàng)积仗,如許可證文件。
你的“helloworld倉(cāng)庫(kù)”是一個(gè)你存放想法蜕猫、資源寂曹、甚至與他人分享和討論事物的地方。
To create a new repository
In the upper right corner, next to your avatar or identicon, click
and then selectNew repository.
Name your repository hello-world.
Write a short description.
Select Initialize this repository with a README.
Click Create repository.
創(chuàng)建新的存儲(chǔ)庫(kù)
在右上角丹锹,在你的頭像或識(shí)別圖標(biāo)邊上稀颁,點(diǎn)擊
然后選擇新的存儲(chǔ)庫(kù)芬失。
給存儲(chǔ)庫(kù)命名“hello world”楣黍。
寫(xiě)一個(gè)簡(jiǎn)短的描述。
選擇:Initialize this repository with a README.(用README初始化存儲(chǔ)庫(kù))
點(diǎn)擊:Create repository(創(chuàng)建存儲(chǔ)庫(kù))
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.
步驟2.創(chuàng)建一個(gè)分支
分支棱烂,是在工作于一個(gè)存儲(chǔ)庫(kù)下的同時(shí)創(chuàng)建的不同版本時(shí)的體現(xiàn)租漂。
默認(rèn)情況下,您的存儲(chǔ)庫(kù)有一個(gè)名為Master(主)的分支颊糜,它被認(rèn)為是最終分支哩治。我們?cè)诒WC讓他們成為最終版之前,用分支來(lái)做實(shí)驗(yàn)和編輯衬鱼。
When you create a branch off the master branch, you’re making a copy, or snap shot, of masteras 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:
1.The master branch.
2.A new branch called feature(because we’re doing ‘feature work’ on this branch)
3.The journey that feature takes before it’s merged(融合) into master
當(dāng)你從主分支創(chuàng)建一個(gè)分支時(shí)业筏,你正在復(fù)制一個(gè)拷貝,或者是快照鸟赫,就像它在那個(gè)時(shí)間點(diǎn)一樣蒜胖。如果有人在您的分支工作時(shí)對(duì)主分支進(jìn)行了更改消别,您可以將這些更新拖進(jìn)去。
這個(gè)圖表顯示:
1.一個(gè)主進(jìn)程
2.一個(gè)叫做特性的新分支(因?yàn)槲覀冊(cè)谶@個(gè)分支上做了“功能工作”)
3.一段將功能特性在合并到主進(jìn)程之前所進(jìn)行的旅程
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.
你保存過(guò)不同版本的文件嗎台谢?像:
story.txt
story-joe-edit.txt
story-joe-edit-reviewed.txt
分支機(jī)構(gòu)在GitHub存儲(chǔ)庫(kù)里完成類(lèi)似的目標(biāo)寻狂。
在GitHub上,我們的開(kāi)發(fā)人員朋沮,作家蛇券,設(shè)計(jì)師用分支讓bug修復(fù)和功能工作從我們的主分支上分離開(kāi)來(lái)。當(dāng)更改準(zhǔn)備就緒時(shí)樊拓,它們將分支合并到主目錄中纠亚。
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.
創(chuàng)建新分支
去你的新存儲(chǔ)庫(kù)“hello world”。
單擊下拉框的文件列表頂部筋夏,表示分支:主流程菜枷。
命名一個(gè)分支名稱“readme-edits”,輸入到新的分支文本框中叁丧。
選擇藍(lán)色創(chuàng)建分支框或單擊鍵盤(pán)上的“Enter”啤誊。
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.
現(xiàn)在你有了兩個(gè)分支,主流程master和readme-edits拥娄。它們看起來(lái)完全一樣蚊锹,但長(zhǎng)度不同!接下來(lái)稚瘾,我們將向新分支添加更改牡昆。
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.
好極了!現(xiàn)在,您在您的readme-edits分支的代碼視圖中摊欠,這是一個(gè)主副本丢烘。讓我們做一些編輯。
在GitHub上些椒,保存的變化稱為保證(版本記錄)播瞳。每個(gè)版本記錄都有一個(gè)關(guān)聯(lián)的提交消息,這是解釋為什么做出了特定更改的說(shuō)明免糕。提交信息時(shí)對(duì)每一次改版做了一次歷史快照赢乓,因此其他參與者可以理解您所做的工作和原因。
Make and commit changes
Click theREADME.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.
作出并提交更改
點(diǎn)擊readme.md文件石窑。
單擊文件視圖右上角的鉛筆圖標(biāo)進(jìn)行編輯牌芋。
在編輯器中,寫(xiě)一點(diǎn)關(guān)于你自己的文章松逊。
編寫(xiě)描述您的更改的提交消息躺屁。
單擊Commit changes 按鈕。
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.
這些更改將只對(duì)readme-edits 分支下的README文件生效经宏,所以現(xiàn)在這個(gè)分支包含與主流程不同的內(nèi)容犀暑。
Step 4. Open a Pull Request
Nice edits! Now that you have changes in a branch off of master, you can open apull request.
Pull Requests are the heart of collaboration on GitHub. When you open apull 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.
做的好極了!既然母怜,您已經(jīng)改變了一個(gè)主干的分支余耽,你可以打開(kāi)一個(gè)pull請(qǐng)求。
pull請(qǐng)求協(xié)作是GitHub上合作工作的核心苹熏。當(dāng)你打開(kāi)一個(gè)pull的請(qǐng)求碟贾,表示你提出了你的更改,并且邀請(qǐng)其他人參與評(píng)審轨域,然后拉著你的貢獻(xiàn)并融合到他們的分支中去袱耽。pull請(qǐng)求可以從從分支的內(nèi)容顯示出差別或差異。這些變化干发,添加和刪減將用綠色和紅色表示朱巨。
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.
一旦你做出了建議,你甚至可以在代碼完成之前開(kāi)一個(gè)拉請(qǐng)求并開(kāi)始討論枉长。
通過(guò)使用GitHub提到的系統(tǒng)拉你的請(qǐng)求消息冀续,你可以向特定的人或團(tuán)隊(duì)獲取反饋,無(wú)論他們?cè)诖髲d或10個(gè)時(shí)區(qū)以外必峰。
您甚至可以在自己的存儲(chǔ)庫(kù)中打開(kāi)拉請(qǐng)求并合并它們洪唐。
這是一種很好的方式來(lái)學(xué)習(xí)GitHub流程,在你為更大的項(xiàng)目工作之前吼蚁。
Open a Pull Request for changes to the README
更改readme時(shí)凭需,打開(kāi)pull 請(qǐng)求
Click the Pull Request tab, then from the Pull Request page, click the greenNew pull request button.
單擊 Pull Request? 按鈕,然后從拉請(qǐng)求頁(yè)肝匆,單擊綠色的New pull request 按鈕粒蜈。
In theExample Comparisons box, select the branch you made,readme-edits, to compare with master(the original).
在示例比較框中,選擇您創(chuàng)建的分支旗国,readme-edits枯怖,與主(原件)進(jìn)行比較。
Look over your changes in the diffs on the Compare page, make sure they’re what you want to submit.
在對(duì)比頁(yè)面看看你更改的不同之處粗仓,確保他們你想提交嫁怀。
When you’re satisfied that these are the changes you want to submit, click the big green Create Pull Requestbutton.
當(dāng)您滿意這些是您想要提交的更改時(shí),單擊綠色 Create Pull Request按鈕借浊。
Give your pull request a title and write a brief description of your changes.
給你的pull 請(qǐng)求一個(gè)標(biāo)題,并寫(xiě)一個(gè)簡(jiǎn)短的描述你的變化萝招。
When you’re done with your message, clickCreate pull request!
Tip: You can useemojianddrag and drop images and gifsonto comments and Pull Requests.
完成消息后蚂斤,單擊“Create pull request”!
提示:你可以使用表情符號(hào)和圖片拖放圖片或gif到評(píng)論中去槐沼,然后pull請(qǐng)求曙蒸。
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 requestbutton to merge the changes into master.
Click Confirm merge.
Go a head and delete the branch, since its changes have been incorporated, with the Delete branch button in the purple box.
在這最后一步中捌治,是時(shí)候把你的更改放在一起了——將你的 readme-edits分支合并到主流程中。
單擊綠色Merge pull request按鈕纽窟,將更改合并到主目錄中肖油。
單擊確認(rèn)合并Confirm merge.。
繼續(xù)刪除分支臂港,因?yàn)樗母囊驯缓喜⑸梗谧仙蛑惺褂昧藙h除分支按鈕。
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
慶祝审孽!
完成本教程县袱,你已經(jīng)學(xué)會(huì)了如何創(chuàng)建一個(gè)項(xiàng)目并在GitHub上做一個(gè)拉的要求!
以下是你在本教程中完成的內(nèi)容:
創(chuàng)建了一個(gè)開(kāi)源庫(kù)
開(kāi)始一個(gè)新的分支和管理
改變一個(gè)文件并提交這些更改GitHub
打開(kāi)和合并拉請(qǐng)求
Take a look at your GitHub profile and you’ll see your newcontribution squares!
To learn more about the power of Pull Requests, we recommend reading theGitHub Flow Guide. You might also visit GitHub Exploreand get involved in an Open Source project
Tip: Check out our otherGuides,YouTube ChannelandOn-Demand Trainingfor more on how to get started with GitHub.
要在你的GitHub的簡(jiǎn)介一看佑力,你會(huì)看到你的新貢獻(xiàn)廣場(chǎng)式散!
了解更多關(guān)于拉要求的權(quán)力,我們推薦閱讀GitHub導(dǎo)流打颤。你也可以訪問(wèn)GitHub的探索和參與的一個(gè)開(kāi)源項(xiàng)目中去
提示:查看我們的其他指南暴拄,YouTube頻道和點(diǎn)播培訓(xùn)更多關(guān)于如何開(kāi)始使用GitHub。