Distributed version control system git (ii): GitHub

Source: Internet
Author: User

Preface

But anyone who likes to study technology or listen to what Daniel has said should at least have heard of GitHub. Specifically not introduced, do not understand to understand, the main function of course is code hosting, there are a variety of Daniel writing projects. This chapter is not just a description if you are associated with GitHub, because GitHub is a remote repository, actually in the company, but also to give you a remote repository address to you, you clone, and then develop, so the following operations can be consistent with the company remote repository operations.

Connect to GitHub1. Of course it is https://github.com2 to register a github account. To create an SSH key

Open git Bash, enter the following command, and then return to

    ssh-keygen-t-C‘[email protected]‘       

Next go to C:\Users\Administrator, will find a more. SSH folder, the generated key is in here again.
Where Id_rsa is its own key, Id_rsa_pub is the public key, is the external key, give it to the party that needs to connect, it adds this to go in, you can connect.

3. GitHub add local public key

Go to GitHub settings and find ssh and GPG Keys

The id_rsa_pub in the previous build. SSH folder is opened in Notepad and copied out to paste in.

4. Test Connection
    ssh -T git@github.com

Note the middle need to confirm the connection, enter Yes, you can see the certification success! In addition, a known_hosts file is generated under the. SSH path, which is a bit of GitHub information that identifies a connection to GitHub and has been identified.

Local –>github

That is, the local project was last on GitHub.

1. You must first create an empty project on GitHub.

2. Connect with the project, push content

After adding the success, you can see the following interface, prompting you how to use the command to connect.

    add origin [email protected].com:你github名字/testgithub.git    push -u origin master

Add a remote repository connection, and then push the contents of the current branch master to the remote repository Master branch

Since the remote library is empty, when we first push the master branch, with the-u parameter, git will not only push the local master branch content to the remote new Master branch, but also associate the local master branch with the remote Master branch. You can simplify the command at a later push or pull.

You can see that the push is successful, and there's been a change on GitHub.

3. Modify file push to remote repository GitHub

First you can see that after the push, both sides of the file content is the same, now we modify the local file, and then pushed to the GitHub remote repository.

Modify the local file.

Then you need to do the following

    • Add to Staging Area
    • Submit to Local repository
    • Push to remote repository

After submitting the push, review the GitHub file and find that it has been successfully changed to indicate a successful push.

github–> Local once a local project is associated with a GitHub project 1. Modify the content of the GitHub file, equivalent to someone else modifying the file, submitted to the remote repository GitHub.

2. Pull the contents of the/pull remote repository
    git pull origin master                   // 拉取远程版本库master分支的内容

second, only in the case of the GitHub project path

In general, a new company will give you a git address for your remote project repository, and you will need to clone a project to the local repository.

cloning a remote repository to a local
    git clone [email protected].com:你github名字/testgithub.git

For example, I cloned the remote repository Testgithub project into my workspace.

Conflict Case Processing

For example, now that I have modified the file on GitHub and then changed the same place locally, there will be a conflict.

GitHub

Local:

Note: The local code here has been committed to the local repository.

This time, if the local push code, will prompt the error.

Therefore, it is common to pull the code from the remote code base before pushing the push to the remote repository.

Can see the a.txt file conflict, and then the command line into the merging mode, this time we can open the a.txt, the conflict is resolved, and then add a.txt to Staging area, then commit, and then push, OK.

Distributed version control system git (ii): 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: 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.