GitHub Remote Repository

Source: Internet
Author: User

Because the transfer between the local git repository and the GitHub repository is encrypted via SSH, set the

1th step: Create SSH Key. In the user home directory, see if there is no. ssh directory, if there is, then look at this directory there are no Id_rsa and id_rsa.pub these two files, if already have, can jump directly to the next step. If not, open the shell (open git Bash under Windows) and create SSH Key:

Ssh-keygen " [email protected] "

You can find the. SSH directory in the user's home directory, there are Id_rsa and id_rsa.pub two files, these two are SSH key key pair, Id_rsa is the private key, can not be disclosed, Id_rsa.pub is the public key, you can safely tell anyone.

2nd step: Login to GitHub, open "Account Settings", "SSH Keys" page:

Then, click "Add SSH Key", fill in any title, paste the contents of the Id_rsa.pub file in the Key text box

Why does GitHub need SSH key? Because GitHub needs to recognize that your push submission is actually pushed by you, not someone else impersonating it, and Git supports the SSH protocol, so if GitHub knows your public key, you can confirm that only you can push it.

Of course, GitHub allows you to add multiple keys. Assuming you have a number of computers, you can submit them at the company in a moment, and at home, just add each key to GitHub and push it to GitHub on every computer.

Finally, friends can see the Git repository, which is hosted on GitHub for free (but only you can change it). So don't put sensitive information in it.

To add a remote library

Run Git bash in the root directory of the local repository as follows

$ git Remote add origin [email protected]:zcynine/hello-world.git

After adding, the name of the remote library is origin , this is the default for Git, or can be changed to another, but origin this name is known as a remote library.

Next, you can push all the contents of the local library to the remote library:

$ Git push-u Origin Master

Since the remote library is empty, the first time we push master a branch, with -u parameters, Git will not only master push the local branch content of the remote new master branch, but also the local master branch and the Remote master Branch Association, You can simplify the command at a later push or pull.

$ GIT push origin master

Cloning from a remote library

$ git clone [email protected]:zcynine/hello-world.git

You may also notice that GitHub gives more than one address and can also use such an https://github.com/zcynine/hello-world.git address. In fact, GIT supports a variety of protocols, git:// using SSH by default, but can also use https other protocols.

With the https exception of slow speed, one of the biggest problems is that each push must enter a password, but in some companies that only open HTTP ports, the protocol cannot be used ssh https .

Branch Branch

To view branches:git branch

To create a branch:git branch <name>

To switch branches:git checkout <name>

Create + switch Branches:git checkout -b <name>

Merge a branch to the current branch:git merge <name>

To delete a branch:git branch -d <name>

GitHub Remote Repository

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.