How to deploy your GitHub warehouse to GitHub pages (GO)

Source: Internet
Author: User

Original address: Http://www.cnblogs.com/yuanzm/p/3945814.html#commentform

Many times I have been thinking about a problem, we encounter a variety of problems every day, and then we need to continue to Google, Baidu, to achieve our goal to solve the problem. But in this process, we can always see, for the same problem, there are always a lot of errors, copy of the blog, the library and even the days of Baidu know, time and again slowed down our progress in solving the problem. Even worse, this copy is not a quality of quantity, so we always hope that whenever we Google or Baidu, we can solve the problem we need to solve the most quickly. It seems unrealistic, however, that it is almost impossible to prohibit this senseless plagiarism when everyone has the right to publish. Clearly aware of this, I find it more effective that everyone who posts a blog or is active in a question and answer site should be refined and accurate in their own blog or answer, which is, in a sense, a duty and responsibility.

Of course, it's a bit far ahead, so let's talk about the legendary GitHub pages today. As mentioned above, each blog should be the remedy, so this article by default you have a GitHub account, installed git and familiar with basic git operations, just need to find the knowledge to deploy GitHub pages.

As a tutorial, it is important to maximize the fool, this article will start from a new GitHub warehouse to the successful deployment of GitHub pages step-by-step resolution.

First step: Create a new GitHub repository "Hello-ghpages":

Now we have an empty warehouse with only readme.md and licence files, and note that the branch that is now in is "master". This is emphasized because the next step must be to clarify which branch the GitHub page is under, and this will be explained later.

Step Two: Click "Settings" on the right column of the page to jump to the project Settings screen:

Step three: In the setup screen we can see that there is a section titled "Github Pages", click on the "Automatic page Generator" button on this piece:

Fourth step: On the "New Project Site" page, you need to be aware of the "tracking ID" at the bottom of the page. The function of "tracking ID" is to use Google's Analystics function, which can analyze website data such as the amount of traffic on your website and not fill it out. If you need to use this feature, you can refer to the link https://support.google.com/analytics/answer/1032385?hl=en. Then click on the "Continue to Layout" button.

The fifth step, set the theme, will be able to publish:

That way, we'll be able to access the page we just posted via the link: http://username.github.io/hello-ghpages/, where username is the name of your GitHub account. According to the blogger experience, the first deployment, the waiting time is relatively long, about 10 minutes to 15 minutes or so. So if you immediately visit the page you just published may appear 404 errors, do not worry slowly wait for more than 10 minutes, will get the effect you want:

At this point we have completed the deployment of GitHub pages, but at this time we are faced with two issues, first: Only two files were originally generated from the repository, there are no files that define the GitHub pages style and content that we see now; second, since we don't define these files, And the files that we see have to be real, where are these files placed? The answer relates to the branch we mentioned at the outset. When we use the "Automatic page Generator" feature, GitHub automatically creates a "Gh-pages" branch under the "master" branch of your project, and the code inside this branch defines the github that we just saw for the successful deployment. The content and style of the pages page.

I think it is necessary to introduce the concept of branching briefly here. Branches are divided into two, one is seen above, this is called a remote branch , and the other is when we use Git for versioning, called the local branch . When using Git for versioning, a commit object is generated for each commit, and the Commit object contains the following:

    • Commit Information metadata: Contains information about the submitter, author, time of submission, etc.
    • An index that contains a pointer to the tree object (root directory): Before committing, Git calculates the checksum for each subdirectory and then saves those directories as tree objects in the Git repository. The index in the commit object points to this object. Take a look at this picture in pro git to get a good idea:

After a certain understanding of the submission, the branch is better understood that the branch in Git is essentially a mutable pointer to a commit object. In practice, let's analyze: When creating a new GitHub repository, we can see from the diagram above that GitHub automatically creates a commit called "Initial commit", and creates a new master branch, which is pointing to " Initial Commit "commits the corresponding commit object; When you deploy GitHub pages, GitHub creates a new branch and creates a commit" create Gh-pages branch via Github. " You can take the above process as a few commands:

1  git branch gh-pages    //Create a new Gh-pages branch under the Master branch 2  git checkout gh-pages    //switch to the newly created Gh-pages branch 3  Git rm-rf.        Because the contents of the Master branch and the Gh-pages branch are completely different, the first empty all Files 4  //In the empty folder to customize the new file, that is, the above see the Gh-pages branch of the file 5  git Add.    Track your own defined files 6  git commit-m "Create gh-pages branch via Github"    //Submit this modification   

So far, you've felt that a question should be how to see the GitHub pages now as I want to see them, and here you need git.

Sixth step: Clone remote repository to Local:

Seventh step: Clone down by default is the Master branch, so we see in the folder is the master branch corresponding content. And we need to edit the Gh-pages branch, because this branch is able to define the content and style of GitHub pages. We need to execute the following command:

The above command means that a new branch is created locally, the name of the local branch is called "Gh-pages", the newly created branch is differentiated under the "Origin/gh-pages" branch of the remote branch and switched to the newly created "Gh-pages" branch, We see the contents of the remote branch "Gh-pages" in the file under "Hello-ghpages" in the folder:

Eighth step: Delete all the files inside, of course, it is best not to delete directly, but through the git command, that will be more convenient and fast.

Nineth step: So far, this folder is empty, we create a new index.html file inside, define some content inside, and commit to the current branch.

Tenth step: Submit to the remote branch to see the effect:

11th Step: Check the effect, haha:

We're done here, hey. Let's review what we need to master throughout the tutorial is how to differentiate remote branches locally and customize the contents of remote branches. The above index.html is the home page of GitHub pages, where you can slowly expand the content you need to display, all as shown in the tutorial. If you have any questions or comments, please feel free to ask in the comments below.

Finally, I would like to say a little off-topic, if you think this blog is well written and hope to be reproduced to their own blog, please specify the reprint address: http://www.cnblogs.com/yuanzm/p/3945814.html, this is the most basic respect for bloggers, thank you.

How to deploy your GitHub warehouse to GitHub pages (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.