GitHub Tutorial (iii) local warehouse hosting to GitHub

Source: Internet
Author: User
Tags git commands

This article begins with a special statement: Since the GitHub tutorial is a GitHub sub-chapter of the GIT series, the GitHub tutorial will no longer detail the GIT operations commands and their usage, and I'll go through the git action commands as needed. If the reader needs to learn or review git commands, you can refer to the Git chapter in the GIT series tutorial, or refer to the Liaoche git tutorial, Liaoche Teacher's git tutorial is very good, easy to understand.

The first thing you need to do is add a local git public key to your GitHub account so you can bind your account to your GitHub account, as follows:

So far, your local git is already tied to GitHub. How do I verify that the bindings are successful?

ssh-t [email protected]

After entering the above instruction in the local git-bash, if a similar situation occurs, the binding is successful, you can proceed to the next step.


After successfully binding the GitHub account, we need to new repository on the GitHub platform. Specific how to do not repeat the narrative, you can see the GitHub tutorial (a) The use of the guide. The results are similar to the following:

Then we put this remote branch on GitHub (Origin master,master---Repository Main branch tag, Origin---The default remote repository name [alias], modifiable]) clone to a local directory.

$ git clone [email protected]: Account name/project name. Git   //

It is worth noting that thegit clone "url (protocol:git)" command can be used in any directory, as long as it can be opened in this directory git-bash[ should be open, which is available in any directory ].

Now go to the local git repository clone down from the remote repository, which has several files, where . Git refers to the local repository (internal includes the standby zone [index] and repository [Master ]).

In this directory, we use the $ git log command to view the commit history information, as shown in the case analysis

Note: For content such as Git repository, refer to the Series Tutorial git series tutorial (ii) GIT repository directory structure, due to the length of the article, this is no longer discussed here.

So far, you've done half the task---create warehouses from github and copy them locally.


Some things are not clear now that their specific role is not a thing, in the course of use you will slowly have a deeper understanding of these things. 1.1 points to overcome the non-adaptation, to become an expert. Remember that there is a very good saying: because of difficulties, it is easy to succeed . Part of the content I've changed from the command line to eclipse, which reduces the difficulty of getting started with git, and makes it easier for readers to understand git intuitively.

To transfer a local repository to a remote repository via git, your local xxx/master must be different from the relative remote Origin/master.

problem Why must there be a difference between a local git repository and a remote git repository?

Answer This is in fact closely related to how git is implemented. git uses a diff parser (such as Vimdiff) to compare the content between two repositories and then commit the difference. Students can imagine, if now the project has 100G content, but the difference is only 1 m, is not necessary to re-pass the 1G content, and as long as the transmission of 1M content, the speed of the increase is very significant. This is one of the important reasons why Git is so popular.

The project I'm going to upload to GitHub is a friend of mine. Bi-set Project---Public platform Assistant, of course, the project itself is not worth mentioning, the degree of graduation design difficulty you understand, on that grade level.

You can stop for a moment and set up the project with Maven before you continue ...

As for how to build Maven project specifically, this issue is not part of this series of tutorials, you can refer to other materials (such as Maven in Action, Chinese translated into Maven combat).

Wait for a few minutes in this

Questions Why do you choose to build Maven project?

Answer Here I want to explain. 1th, before I do not have Maven project, but to work after the company to find the company using MAVEN to build the project, after the use of this thing is too cool, mom no longer worry about my jar package dependencies, Pom.xml file easy to do (in fact, it is not easy, but compared to the previous kind of pure hand, Come or a little convenient point, purely personal feeling); 2nd, it seems that the open source project on GitHub is based on MAVEN, and you can see that MAVEN is an important trend in project building technology (there are other ways out, you can check it), keep up with the trend of the times.

On his knees, hand over a schematic, excerpt from the Basic principles of Git, " respect for copyright, courtesy of the link ", mainly this kind of diagram itself again and again similar, so just in the original image based on a slight change ...

Now all we have to do is copy the existing MAVEN project code into the working directory, and the working directory (working tree) is where our local maven project should be hiding. CV Dafa ...

With the use of CV Dafa, the result is that, of course, this is just a superficial phenomenon.

Then open eclipse, delete the original MAVEN project, and import the existing Maven project into eclipse. After you Import Existing Maven project, the results are as follows.

If the developer modifies the local code, the eclipse git plugin will have a ">" Arrow on the project, indicating that the working directory has been modified and needs to be submitted to staging area.

Since this is just a simple copy of the MAVEN project to the Git repository, the local repository does not have tracking monitoring (track ) for any of thefiles in this MAVEN project. If we don't believe it, we'll try to take a look at the order and verify if I'm right about it.

It seems that this is the case pinch. Then the problem is coming [from ancient times, deep affection can not stay, only a routine popular. Oh, yes! ]

Questions when will the files be tracked and why?

Answer this thing is still a little bit more complicated, I will pick "cartilage head" gnawing. Git monitoring is tracked only when files in the working directory are included in the repository (at least add to the index area of the repository). The reason is very simple to explain in popular words: C language file pointers do not need to assign address value to be able to manipulate the file? Obviously not. That's the truth here too.

Now that the problem is clear, then the right remedy.

$ git add <file>  //

The GUI interface simplifies command-line operations after Eclipse integrates jgit. In the project, right-click, Team→add to Index, add the working directory modified add to staging area.

Local changes are submitted to Staging Area (index), the Git plugin will prompt for a "↑" small arrow, indicating that the code in staging area needs to commit to the local repository and then push to the remote repository.if it is only a commit to the local repository, the small arrow will still exist and must be push to the remote repository before it disappears.

Take a look at the specific branching situation, and the results of the operation in Eclipse are as shown.

Select commit and push to commit changes to the remote repository

After the project update, the results are as follows

To view the remote repository, github results are as follows

"White cat Black Cat, catch mouse is Good cat", obviously the above Eclipse integration Jgit can help us to complete the task quickly.

It must be noted, though, that while using the Eclipse integrated Jgit plugin to simplify Git's getting started, it can help users quickly use Git, but it's not good for the reader to improve---understand the git principle.

After this tutorial study, perhaps after reading the classmate or foggy, many concepts have not clear understanding grasp, I think this situation is normal, slowly summed up learning it.

GitHub Tutorial (iii) local warehouse hosting to GitHub

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