GIT operations-Remote repositories

Source: Internet
Author: User
Tags site hosted

Our remote repository here uses GitHub (a Web site hosted by a git repository) and requires a GitHub account first.

Connect to local git and GitHub

Because the transfer between the local git repository and the GitHub repository is encrypted via SSH, you need to set:
1. 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 -t rsa -C "[email protected]"
You need to change the email address to your own email address, and then return to the default value, as this key is not used for military purposes, so there is no need to set a password.

If all goes well, 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 leaked out, Id_rsa.pub is the public key, can be assured to tell anyone.

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

After clicking "Add Key":

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.

Add a remote repository

Scenario: After you have created a git repository locally, you want to create a git repository on GitHub and synchronize the two warehouses remotely, so that the repository on GitHub can be used as a backup, and that other people can collaborate through the warehouse

1. Log on to GitHub, then, in the upper right corner, find the "Create a new Repo" button to create a new warehouse:

After successful creation:

2. Associate the Gittest warehouse on GitHub that you just created with the local gittest for the following command:
git remote add origin [email protected]:changjiang007/gitTest.git

After the association, using the command to $ git push -u origin master push all the contents of the local library to the remote library, because the remote library is empty, when we first push the master branch, plus the-u parameter, git will not only push the local master branch content of the remote new Master branch, It also associates the local master branch with the remote Master Branch and simplifies the command (either directly or) at a later push or pull git push origin master git pull .

SSH warning

When you first connect to GitHub using Git's clone or push command, you get a warning:
The authenticity of host ‘github.com (xx.xx.xx.xx)‘ can‘t be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?

This is because Git uses SSH connection, and SSH connection is the first time to verify the GitHub server key, you need to confirm that GitHub key fingerprint information is really from the GitHub server, enter Yes.

Git will output a warning telling you that you have added GitHub key to a trust list on this machine:

Warning: Permanently added ‘github.com‘ (RSA) to the list of known hosts.
This warning will only appear once, and there will be no warning after the operation.

Once the push is successful, you can see the remote library's content on the GitHub page immediately as if it were local:

Cloning from a remote repository

Scenario: There's a repository on GitHub, but not on the local repository, and now it's time to clone this repository from GitHub.
For example: I now have a warehouse on GitHub Iscroll

Then open the git bash Use command locally $ git clone [email protected]:changjiang007/iscroll.git to clone GitHub to the ground

You may also notice that GitHub gives more than one address and can also use such an https://github.com/changjiang007/iscroll.git address. In fact, GIT supports multiple protocols, and the default git://uses SSH, but other protocols such as HTTPS can also be used.

In addition to the slow use of HTTPS, the biggest trouble is that each push must enter a password, but in some only open the HTTP port of the company can not use the SSH protocol and can only use HTTPS.

GIT operations-Remote repositories

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.