Remote Warehouse
1th step: Create SSH Key. In the user home directory, see if there is a .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, you can skip to the next step. If not, open the Shell (open git Bash under Windows) and create SSH Key:
ssh-keygen-t-C"[email protected]"
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:
To add a remote library
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:
At the moment, this learngit warehouse on GitHub 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 Learngit repository, based on GitHub's prompt:
add origin https://github.com/chunhuizhang/learngit.git
Once added, the name of the remote Library is origin, which is the default term for git, or it can be changed to something else, but the name of origin is known as the remote repository.
Next, you can push all the contents of the local library to the remote library:
push -u origin master
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 the master
branch, with the -u
parameters, Git will not only push the local master 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.
From now on, as long as the local commits, you can pass the command:
push origin master
Cloning from a remote library
We talked about how to associate a remote library with a local library and then a remote library.
Now, assuming that we are developing from scratch, the best way is to first create a remote library and then clone from the remote library.
First, log on to GitHub and create a new repository named gittest
:
We tick Initialize this repository with a README
, this GitHub
will automatically create a file for us README.md
. Once created, you can see the README.md
file:
Now that the remote library is ready, the next step is to git clone
clone a local library with a command:
git clone [email protected].com:chunhuizhang/gittest.git
or use the HTTPS protocol:
clone https://github.com/chunhuizhang/gittest.git
In fact, Git supports a variety of protocols , which are used by default git://
ssh
, but can also be used https
for other protocols.
With the https
exception of slow speed, one of the biggest trouble is that each push must enter a password, but in some open http
ports only within the company can not use the SSH protocol https
.
Git Basics (vii)--remote repository (GITHUB)