Git Tutorials (10)--Adding remote libraries

Source: Internet
Author: User

Now, after you've 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 with the warehouse, It was so much.

First, log on to GitHub, and then, in the upper right corner, find the "Create a new Repo" button to create a new warehouse:

In the repository name fill in learngit , the other remains the default settings, click the "Create Repository" button, the successful creation of a new Git repository:

At the moment, this warehouse on GitHub learngit is still empty, and GitHub tells us that we can clone a new repository from this repository, or associate an existing local repository with it, and then push the contents of the local repository to the GitHub repository.

Now, let's run the command under the local repository, based on GitHub's tips learngit :

下一步,就可以把本地库的所有内容推送到远程库上:

 

我运行这个命令的时候会出现这个错误,我猜是因为 我的网络设置了代理,并且公司的网络会有限制,所以才会出现这个
错误。。。。改天带回宿舍试一下

正确应该是这样的

Pushing the contents of the local library to the remote, with git push the command, is actually pushing the current branch master to the remote.

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.

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

From now on, as long as the local commits, you can pass the command:

1 git push Origin master

Push the master latest changes from your local branch to GitHub, and now you have a truly distributed repository!

SSH warning

The first time you use Git clone or push a command to connect to GitHub, you get a warning:

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 the yes return.

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

This warning will only appear once, and there will be no warning after the operation.

If you're really worried about someone impersonating a github server, you yes can match the fingerprint information of GitHub's RSA key with the SSH connection before entering it.

Summary

To associate a remote library, use the command git remote add origin git@server-name:path/repo-name.git ;

Once associated, use the command to git push -u origin master push all the contents of the master branch for the first time;

Thereafter, after each local submission, whenever necessary, you can use the command to git push origin master push the latest changes;

One of the biggest benefits of distributed version systems is that working locally does not have to take into account the existence of remote libraries, which means that there is no Internet connection that works, and SVN refuses to work when it is not connected! When there is a network, and then the local submission push a bit to complete the synchronization, it is very convenient!

 

Git Tutorials (10)--Adding remote libraries

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.