git8--Adding remote libraries

Source: Internet
Author: User

Now the scenario is that you've created a local Git warehouse, and want to GitHub Create a Git Warehouse, and let the two warehouses be synchronized remotely, so that GitHub warehouse can be used as a backup, but also let others through the warehouse to collaborate, there is a lot of one.

First, login GitHub , and then, in the upper-right corner, locate "Create A new repo" button to create a new warehouse:

in the Repository name Fill in learngit , other keep the default settings, click "Create Repository" button, you have successfully created a new Git Warehouse:

At present, in GitHub on this learngit The warehouse is still empty, GitHub tell us that you can clone a new warehouse from this repository, or you can associate an existing local repository with it, and then push the contents of the local repository to GitHub warehouses.

now, we are based on GitHub the prompt, in the local learngit Run command under warehouse:

git remote add origin git@github . com:michaelliao/learngit.git

Please be careful to put the above michaelliao replace it with your own GitHub account name, otherwise, you are locally associated with my Remote library, the association is not a problem, but you later push is not pushed up, because your SSH Key The public key is not in my account list.

once added, the remote library's name is origin , this is Git By default, it can be changed to something else, 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
Counting objects: 19, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (19/19), 13.73 KiB, done.
Total 23 (delta 6), reused 0 (delta 0)
To [email protected]:michaelliao/learngit.git
 * [new branch]      master -> master
Branch master Set to from  origin. 

Push the contents of the local library to the remote, using git push the command, which is actually putting the current branch master push to remote.

Because the remote library is empty, we first push The master When the branch is added -u parameter, git master branch content push remote new master master branching and remote master Branches are associated to simplify the command at a later push or pull.

after the push is successful, you can immediately GitHub the contents of the Remote library on the page are identical to the Local:

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

git push origin master

the local master the latest changes to the branch are pushed to GitHub , now you have a truly distributed repository!

SSHWarning

when you first use Git of the clone or push Command Connection GitHub , you will 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 use ssh connection, and ssh connection on first validation github server key github key Does the fingerprint information really come from the github yes Enter.

Git will output a warning telling you that you have GitHub of the Key added to a trust list for 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.

If you're really worried about someone posing GitHub server, input yes before you can compare GitHub 's RSA Key the fingerprint information whether with SSH the connection gives the same.

Summary

to associate a remote library, use the command git remoteadd origin [email protected]:path/repo-name.git ;

when associated, use the command git push -uorigin master first time Push Master all the contents of the branch;

thereafter, after each local commit, you can use the command git pushorigin master whenever necessary push the latest changes;

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

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