git study notes --- add a remote library

Now the scenario is, you have created a Git repository locally after, want to create a Git repository on GitHub, and let the two warehouses for remote synchronization, so, on the GitHub repository either as a backup, but also allows other people to collaborate through the warehouse, really serve multiple purposes.

First of all, landing GitHub, and then find the "Create a new repo" button in the upper right corner to create a new repository:

github-create-repo-1

In the Repository name filled in learngit, the other to keep the default settings, click "Create repository" button, you successfully created a new Git repository:

github-create-repo-2

Currently, this on the GitHub learngitrepository empty, GitHub tell us, you can clone a new warehouse from the warehouse, you can put an existing local repository associated with it, then the contents of the local repository pushed to GitHub repository .

Now, we have, in accordance with local tips on GitHub learngitrun command Warehouse:

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

Please do note that the above michaelliaoreplace it with your own GitHub account name, otherwise you in your SSH Key is my remote public libraries, local association is no problem associated with, but not after you push a push up, because the key is not in my account list.

After the addition, the library is the name of the remote origin, which is the default, Git is called, can be changed to another, but originthe name to see that this is a remote database.

Next, we can put all the contents of the local repository pushed to the remote repository:

$ git push -u origin master
Counting objects: 20, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (20/20), 1.64 KiB | 560.00 KiB/s, done.
Total 20 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), done.
To github.com:michaelliao/learngit.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'. 

The contents of the local repository pushed to the remote, use git pushthe command, in fact, the current branch masterpushed to the remote.

Because the remote library is empty, the first time we push mastera branch, with the -uparameters, Git will not only local masterremote content push new branch of the masterbranch, but also the local masterbranch and remote masterassociation branch up after command can be simplified push or pull.

After the push, you can immediately see the contents of local and remote databases have been exactly the same in the GitHub page:

github-repo

From now on, as long as the local were submitted, it can be ordered:

$ git push origin master

  

The local masterlast modified branch pushed to GitHub, now, you have a truly distributed repository!

SSH warning

When you first use the Git cloneor pushcommand 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 uses SSH connection, and when the first SSH connection verification Key GitHub server, you need to confirm whether the fingerprint information Key's GitHub GitHub really from the server, enter yespress Enter.

Git will output a warning, telling you have to add GitHub is Key to a trusted list of this machine in the:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

  

This warning will only appear once, the latter operation will not have any warning.

If you are really worried about people posing as GitHub server, enter the yesfront can control the RSA Key GitHub fingerprint information of the same is connected with SSH given.

summary

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

After linking, use the command git push -u origin masterfor the first time to push all the contents of the master branch;

Since then, after each local commit as long as necessary, you can use the command git push origin masterto push the latest modification;

One of the biggest benefits of distributed version is absolutely no need to consider the system of remote libraries exist in the local working, there is no networking can work, but in the absence of SVN is networked to refuse to work in! When there is a network, and then push it to submit local synchronization is complete, really convenient!

Guess you like

Origin www.cnblogs.com/saryli/p/11368803.html