github注册,使用方法

来源:互联网 发布:巴基斯坦取消 知乎 编辑:程序博客网 时间:2024/05/18 03:54

参考一:

https://guides.github.com/activities/hello-world/

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

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.

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.

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 aREADME, 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.

To create a new repository

  1. In the upper right corner, next to your avatar or identicon, click
  1. and then select New repository.
  2. Name your repository hello-world.
  3. Write a short description.
  4. Select Initialize this repository with a README.

new-repo-form

Click Create repository. :tada:

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 tomaster.

When you create a branch off the master branch, you’re making a copy, or snapshot, ofmaster as it was at that point in time. If someone else made changes to themaster branch while you were working on your branch, you could pull in those updates.

This diagram shows:

  • The master branch
  • A new branch called feature (because we’re doing ‘feature work’ on this branch)
  • The journey that feature takes before it’s merged intomaster

a branch

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 ourmaster (production) branch. When a change is ready, they merge their branch intomaster.

To create a new branch

  1. Go to your new repository hello-world.
  2. Click the drop down at the top of the file list that says branch: master.
  3. Type a branch name, readme-edits, into the new branch text box.
  4. Select the blue Create branch box or hit “Enter” on your keyboard.

branch gif

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.

Step 3. Make and commit changes

Bravo! Now, you’re on the code view for your readme-edits branch, which is a copy ofmaster. Let’s make some edits.

On GitHub, saved changes are called commits. Each commit has an associatedcommit 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.

Make and commit changes

  1. Click the README.md file.
  2. Click the
  1. pencil icon in the upper right corner of the file view to edit.
  2. In the editor, write a bit about yourself.
  3. Write a commit message that describes your changes.
  4. Click Commit changes button.

commit

These changes will be made to just the README file on your readme-edits branch, so now this branch contains content that’s different frommaster.

Step 4. Open a Pull Request

Nice edits! Now that you have changes in a branch off of master, you can open a pull request.

Pull Requests are the heart of collaboration on GitHub. When you open a pull request, you’re proposing your changes and requesting that someone review and pull in your contribution and merge them into their branch. Pull requests showdiffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.

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.

Open a Pull Request for changes to the README

Click on the image for a larger version

StepScreenshotClick thePull Request tab, then from the Pull Request page, click the greenNew pull request button.pr-tabSelect the branch you made, readme-edits, to compare withmaster (the original).branchLook over your changes in the diffs on the Compare page, make sure they’re what you want to submit.diffWhen you’re satisfied that these are the changes you want to submit, click the big greenCreate Pull Request button.create-pullGive your pull request a title and write a brief description of your changes.pr-form

When you’re done with your message, click Create pull request!


Tip: You can use emoji and drag and drop images and gifs onto comments and Pull Requests.

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.

  1. Click the green Merge pull request button to merge the changes intomaster.
  2. Click Confirm merge.
  3. Go ahead and delete the branch, since its changes have been incorporated, with theDelete branch button in the purple box.

mergedelete

Celebrate!

By completing this tutorial, you’ve learned to create a project and make a pull request on GitHub!:tada::octocat::zap:

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

Take a look at your GitHub profile and you’ll see your new contribution squares!

If you want to learn more about the power of Pull Requests, we recommend reading theGitHub Flow Guide. You might also visitGitHub Explore and get involved in an Open Source project:octocat:


Tip: Check out our other Guides and YouTube Channel for more GitHub how-tos.

Last updated April 7, 2016


参考二:

http://stormzhang.com/github/2016/05/26/learn-github-from-zero2/

1. 注册 GitHub

先去 GitHub 官网「How people build software · GitHub」注册「Sign Up」个账号,注册页面如下:

这个应该没啥说的,需要填用户名、邮箱、密码,值得一提的用户名请不要那么随便,最好取的这个名字就是你以后常用的用户名了,也强烈建议你各大社交账号都用一样的用户名,这样识别度较高,比如我的博客域名、GitHub、知乎等其他社交账号 ID 都是 stormzhang ,微博是因为被占用了,无奈换了个id,而且这个用户名以后在 GitHub 搭建博客的时候默认给你生成的博客地址就是 http://username.github.io ,所以给自己取个好点的用户名吧。

填好用户名、邮箱、密码紧接着到这一步:

这个是什么意思呢?GitHub 有两种,一种是公开,这种是免费的,就是你创建的项目是开放的,所有人都能看得到;另一种是私有,这种是收费的,这种一般是很多企业在使用 GitHub 的私有仓库在托管自己的项目,这也是 GitHub 的一种盈利模式对于个人你就直接默认选择公开的就行了。

2. 认识 GitHub

注册成功之后你会到 GitHub 的主页面来:

你如果是新注册的可能看到的跟我不一样,因为你们新用户,没有自己的项目,没有关注的人,所以只有一个导航栏。

导航栏,从左到右依次是 GitHub 主页按钮、搜索框、PR、Issues、Gist(这些概念后面会讲的)、消息提醒、创建项目按钮、我的账号相关。

我的 Timeline,这部分你可以理解成微博,就是你关注的一些人的活动会出现在这里,比如如果你们关注我了,那么以后我 star、fork 了某些项目就会出现在你的时间线里。

我的项目,这部分就不用说了,如果你创建了项目,就里就可以快捷访问。

3. GitHub 主页

点击下图的 Your profile 菜单进入到你的个人 GitHub 主页。

还是以我的 GitHub 主页为例:

这么详细应该不会看不懂吧?只不过你的账号可能没有这么丰富,因为你可能啥也没做过,但是如果做全了基本上就会看到跟我一样的了。

4. 设置你的 GitHub

如果你是新注册的 GitHub 账号,是不是觉得很简陋?虽然你没有自己的项目,但是第一步起码要先完善自己的信息,点击如下的 Settings 菜单:

到设置页面来设置一些基本信息:

像头像、Name 建议要设置一个常用的,这两个很有识别性,公开的邮箱也要设置一个,这样那些企业啊、猎头啊就通过这个公开邮箱去联系你,友情提醒:别在 GitHub 把自己的 QQ 邮箱放上去,不显得太 low 了么?没有 gmail 邮箱,起码也得注册个 foxmail、163 邮箱之类的吧。

5. GitHub 基本概念

上面认识了 GitHub 的基本面貌之后,你需要了解一些 GitHub 的基本概念,这些概念是你经常会接触并遇到的。

  • Repository

仓库的意思,即你的项目,你想在 GitHub 上开源一个项目,那就必须要新建一个 Repository ,如果你开源的项目多了,你就拥有了多个 Repositories 。

  • Issue

问题的意思,举个例子,就是你开源了一个项目,别人发现你的项目中有bug,或者哪些地方做的不够好,他就可以给你提个 Issue ,即问题,提的问题多了,也就是 Issues ,然后你看到了这些问题就可以去逐个修复,修复ok了就可以一个个的 Close 掉。

  • Star

这个好理解,就是给项目点赞,但是在 GitHub 上的点赞远比微博、知乎点赞难的多,如果你有一个项目获得100个star都算很不容易了!

  • Fork

这个不好翻译,如果实在要翻译我把他翻译成分叉,什么意思呢?你开源了一个项目,别人想在你这个项目的基础上做些改进,然后应用到自己的项目中,这个时候他就可以 Fork 你的项目,这个时候他的 GitHub 主页上就多了一个项目,只不过这个项目是基于你的项目基础(本质上是在原有项目的基础上新建了一个分支,分支的概念后面会在讲解Git的时候说到),他就可以随心所欲的去改进,但是丝毫不会影响原有项目的代码与结构。

  • Pull Request

发起请求,这个其实是基于 Fork 的,还是上面那个例子,如果别人在你基础上做了改进,后来觉得改进的很不错,应该要把这些改进让更多的人收益,于是就想把自己的改进合并到原有项目里,这个时候他就可以发起一个 Pull Request(简称PR) ,原有项目创建人就可以收到这个请求,这个时候他会仔细review你的代码,并且测试觉得OK了,就会接受你的PR,这个时候你做的改进原有项目就会拥有了。

  • Watch

这个也好理解就是观察,如果你 Watch 了某个项目,那么以后只要这个项目有任何更新,你都会第一时间收到关于这个项目的通知提醒。

  • Gist

有些时候你没有项目可以开源,只是单纯的想分享一些代码片段,那这个时候 Gist 就派上用场了!

6. 创建自己的项目

点击顶部导航栏的 + 可以快速创建一个项目,如下图:

创建一个项目需要填写如上的几部分:项目名、项目描述与简单的介绍,你不付费没法选择私有的,所以接着只能选择 public 的,之后勾选「Initialize this repository with a README」,这样你就拥有了你的第一个 GitHub 项目:

可以看到这个项目只包含了一个 README.md 文件,但是它已经是一个完整的 Git 仓库了,你可以通过对它进行一些操作,如watch、star、fork,还可以 clone 或者下载下来。

这里提一下 README.md ,GitHub 上所有关于项目的详细介绍以及 Wiki 都是基于 Markdown 的,甚至之后在 GitHub 上搭建博客,写博客也是如此,所以如果还不懂 Markdown 语法的,建议先去学习下。推荐一篇学习 Markdown 的文章给你们:

献给写作者的 Markdown 新手指南


0 0
原创粉丝点击