初识 GitHub

来源:互联网 发布:阿里云吧 编辑:程序博客网 时间:2024/05/12 17:46


主要参考官方的bootcamp https://help.github.com/articles/set-up-git/

Set Up Git

在GitHub的心脏是一个开源的版本控制系统(VCS)称为Git的。 Git是负责一切GitHub上有关这发生在本地计算机上。
如果你不喜欢使用命令行,现在,GitHub上,您可以完成许多Git的相关操作,而无需使用命令行,其中包括:
  • Creating a repository
  • Forking a repository
  • Being social

Setting up Git

  1. 1 下载; Download and install the latest version of GitHub for Windows. This will automatically install Gitand keep it up-to-date for you.
  2. 2 打开Git Shell; On your computer, open the Git Shell application.
  3. 3 git你的名字;Tell Git your name so your commits will be properly labeled. Type everything after the $ here:

    git config --global user.name "YOUR NAME"
  4. 4 git你的e-mail;Tell Git the email address that will be associated with your Git commits. The email you specify should be the same one found in your email settings. To keep your email address hidden, see "Keeping your email address private".

    git config --global user.email "YOUR EMAIL ADDRESS"

Next steps: Authenticating with GitHub from Git


两种方式认证git;https/SSH

When you connect to a GitHub repository from Git, you'll need to authenticate with GitHub using either HTTPS or SSH.

Connecting over HTTPS (recommended)

If you clone with HTTPS, you can cache your GitHub password in Git using a credential helper.

Connecting over SSH

If you clone with SSH, you must generate SSH keys on each computer you use to push or pull from GitHub.


Create a new repository on GitHub

  1. 1 点击创建 In the upper-right corner of any page, click , and then click New repository.
    2 Create a short, memorable name for your repository. For example, "hello-world".
  2. 3 Optionally, add a description of your repository. For example, "My first repository on GitHub."

  3. 4 Choose between creating a public or private repository.
  4. 公共库是入门的绝佳选择!他们看到在GitHub上的任何用户,这样你就可以从一个协作社区受益。
    私人库需要更多的设置。他们只提供给你,仓库主人,以及您选择与之共享的任何合作者。
    • Public repositories are a great choice for getting started! They're visible to any user on GitHub, so you can benefit from a collaborative community.
    • Private repositories require a little more setup. They're only available to you, the repository owner, as well as any collaborators you choose to share with. Private repositories are only available for paid accounts. For more information, see "What plan should I choose?.
    • 5 Select Initialize this repository with a README.
    • 6 Click Create repository.
    Congratulations! You've successfully created your first repository, and initialized it with a README file.

Commit your first change

commit is like a snapshot of all the files in your project at a particular point in time.

When you created your new repository, you initialized it with a README file. README files are a great place to describe your project in more detail, or add some documentation such as how to install or use your project. The contents of your README file are automatically shown on the front page of your repository.

 Let's commit a change to the README file.



  1. 1 打开  In your repository's list of files, click README.md.
  2. 2 Above the file's content, click .
  3. On the Edit file tab , type some information about yourself.

  4. 4 Above the new content, click Preview changes
    5 Review the changes you made to the file. You'll see the new content in green.
  5. 6 At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.

  6. 7 Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.


  7. Click Propose file change.


fork就是一个仓库的副本。分叉存储库可以让你自由地尝试改变,而不会影响原来的项目。

最常见的是,叉是用来或者提出修改别人的项目,或者用别人的项目为起点,为您自己的想法。

Fork an example repository

Forking a repository is a simple two-step process. We've created a repository for you to practice with!

  1. 1  On GitHub, navigate to the octocat/Spoon-Knife repository.
  2. 2 In the top-right corner of the page, click Fork.

  3. That's it! Now, you have a fork of the original octocat/Spoon-Knife repository.

Keep your fork synced

You might fork a project in order to propose changes to the upstream, or original, repository. In this case, it's good practice to regularly sync your fork with the upstream repository. To do this, you'll need to use Git on the command line. You can practice setting the upstream repository using the same octocat/Spoon-Knife repository you just forked!

Step 1: Set Up Git

If you haven't yet, you should first set up Git. Don't forget to set up authentication to GitHub from Git as well.

Step 2: Create a local clone of your fork

Right now, you have a fork of the Spoon-Knife repository, but you don't have the files in that repository on your computer. Let's create a clone of your fork locally on your computer.

  1. 1 On GitHub, navigate to your fork of the Spoon-Knife repository.
  2. 2 复制地址 In the right sidebar of your fork's repository page, click  to copy the clone URL for your fork.

  3. 3 Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).

  4. 4 Type git clone, and then paste the URL you copied in Step 2. It will look like this, with your GitHub username instead of YOUR-USERNAME:

    git clone https://github.com/YOUR-USERNAME/Spoon-Knife
  5. 5  Press Enter. Your local clone will be created.

    git clone https://github.com/YOUR-USERNAME/Spoon-Knife# Cloning into `Spoon-Knife`...# remote: Counting objects: 10, done.# remote: Compressing objects: 100% (8/8), done.# remove: Total 10 (delta 1), reused 10 (delta 1)# Unpacking objects: 100% (10/10), done.

Now, you have a local copy of your fork of the Spoon-Knife repository!

Step 3: Configure Git to sync your fork with the original Spoon-Knife repository

When you fork a project in order to propose changes to the original repository, you can configure Git to pull changes from the original, or upstream, repository into the local clone of your fork.

  1. 1 On GitHub, navigate to the octocat/Spoon-Knife repository.
  2. 2 In the right sidebar of the repository page, click  to copy the clone URL for the repository.
  3. 3 Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).
  4. 4 Change directories to the location of the fork you cloned in Step 2: Create a local clone of your fork.

    • To go to your home directory, type just cd with no other text.
    • To list the files and folders in your current directory, type ls.
    • To go into one of your listed directories, type cd your_listed_directory.
    • To go up one directory, type cd ...
  5. 记住进入刚才的目录下面
    5 Type git remote -v and press Enter. You'll see the current configured remote repository for your fork.

    git remote -v# origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)# origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
  6. 6 Type git remote add upstream, and then paste the URL you copied in Step 2 and pressEnter. It will look like this:

    git remote add upstream https://github.com/octocat/Spoon-Knife.git
  7. 7 To verify the new upstream repository you've specified for your fork, type git remote -v again. You should see the URL for your fork as origin, and the URL for the original repository asupstream.

    git remote -v <span style="font-family: inherit; font-style: inherit; font-variant: inherit; line-height: inherit;"># origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)# origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)# upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)# upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)</span>

Now, you can keep your fork synced with the upstream repository with a few Git commands. For more information, see "Syncing a fork."


Follow People

When you follow someone on GitHub, you'll get notifications on your dashboard about their activity.

Once you are on one of their pages, click the "follow" button.

Follow user button

Watch A Project

At some point you may want to stay up-to-date with a specific project. When you're on a project page, you can click the Watch button at the top of the page.

Watch repository button

When the owner updates the project, you'll see what happened in your dashboard.

More Things You Can Do

You've done some of the most basic social interaction GitHub has to offer, but don't stop there! Check out these other social features:

Pull Requests

Pull Request Button

You may find yourself wanting to contribute to someone else's project, whether to add features or to fix bugs. After making changes, you can let the original author know about them by sending a pull request.

Issues

Issues Button

When you are collaborating on a project with someone, you sometimes come across problems that need to be fixed. Each repository has an Issues section to help you keep track of these problems.

Organizations

Switch account context dropdown

Have you found yourself wishing you could collaborate with multiple people on one project? You can manage everyone with organizations! With an organization you can establish teams with special permissions, have a public organization profile, and keep track of activity within the organization.

Explore

Star a project

Discover interesting projects in the Explore GitHub and Trending page sections. You can then star projects that you find interesting and want to come back to later—just visit your stars page to see all your starred projects.



第一次学习使用GitHub,很多都不会,请哪位大神多多提点指教啊。谢谢啦



0 0
原创粉丝点击