This document records the connection of remote libraries and the cloning and push of libraries.
Introduction to remote Warehouses
Git is a distributed version control system, and the same git repository can be distributed across different machines. There is a machine with an original repository, and since then, other machines can "clone" the original repository, and each machine's repository is actually the same, and there is no primary and secondary points.
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,
There's a foreign site called GitHub , which provides a git repository hosting service, so just sign up for a GitHub account to get a git remote repository for free. Similar sites have many, such as: the domestic open source China's git(this article uses the foreign GitHub, the speed is a bit slow)
SSH protocol Configuration
When synchronizing with a remote repository, we can use the HTTPS protocol or SSH protocol to make the SSH protocol more secure and faster. Take different approaches according to your needs. So I use a secure faster SSH protocol.
Check to see if the key pair required for SSH has been generated
// View your system's home directory pwd/home/ubuntu//. ssh files are hidden [email protected]:~$
ls -
a. . BASHRC . Dbus . Iceauthority. PKI . sudo_as_admin_successful public ... Cache . DMRC Joe presage . Xauthority template . bash_history . Compiz. gconf . Local profile . Xsession- errors video . Bash_logout . config . gitconfig. Mozilla . ssh . xsession-errors.old pictures // enter. SSH to view the files inside
CD. SSH/
[email protected]:~/. SSH ls id_rsa id_rsa.pub known_hosts// 3 files are private keys, public keys, and associated hosts that have been established with each other. // Main is the first 2 keys of the file. You can also check what's inside. // if not, then make the following settings
Set the SSH secret key
// the command is as follows (email for your own AH) &Ssh-keygen
- t rsa-c "[email protected]"
// during the setup process, you may be asked some questions or set some parameters (don't panic, you can take a patient look at these questions and improve your English.) Use the default value (direct carriage return) or Yes. //Then look in the user's home directory to find the 2 files that already have the secret key.
Tell the remote library your public key to establish an SSH connection.
Use your registered account, log in later follow the image instructions (also do not have to follow the below, you can also explore this site yourself).
Add a remote connection
After success, the first library, the site will give you a hint of information, as follows (there are 2 of the protocol HTTP and SSH, you can choose, there are some tips below to help, do not read a bit. )
Download remote Libraries and submit
Find out more about the library (page below)
// Run the command under the local learngit repository , as prompted by GitHub:
git remote add origin [email protected]:michaelliao/learngit.git
// [email Protected]:michaelliao/learngit.gi is replaced with a copy of SSH, where the name of the remote library is the Origin // push local content to the remote repository
git push-u Origin master
//is actually pushing the current branch master to the remoteCounting objects: +, Done. Delta compression using up to4threads.compressing objects: -% ( +/ +), Done. Writing objects: -% ( +/ +),13.73KiB, Done. Total at(Delta6), reused0(Delta0) to [email Protected]:michaelliao/Learngit.git* [New branch] Master,Masterbranch Master set up to track remote branch master from Origin.//Since the remote library is empty, when we first push the master branch, with the-u parameter, git will not only push the local master branch content to the remote new Master branch, but also associate the local master branch with the remote Master branch. 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:$
git push Origin master
SSH warning on connection and push
//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 the sure you want to continue connecting (yes/no)?//This is because Git uses SSH connections, and SSH connects to the first time you verify the GitHub server key, you need to confirm GitHub's//Key's fingerprint information is really from GitHub's server, enter Yes to return. //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.
Clone Library
It says so much mainly is to establish the connection, the connection we only build once to be possible. The most common uses are clones and push libraries.
ls // only one local library Learngit[email protected]:
mkdir testgit
// Create a new local library
CD testgit/
[email protected]: ls [email protected]:
git init
// Initialization of the library Initializes an empty Git repository at/home/ubuntu/joe/testgit/.git/[email protected]:
git clone [email protected]:joesgit15/git-test.git
// clone library cloning to '
ls
// cloning success git-test[email protected]:~/joe/testgit$ cd git-test/[email protected]:ls readme.md
Push the practice library again
ls Readme.md[email protected]:
git status
// View the status of a library 'origin/master' consistent . No files to submit, a clean workspace [email protected]:
VI readme.md
//Modify a file[Email protected]:~/joe/testgit/git-test$ git status in branch master your branch and upstream branch'Origin/master' consistent . Changes not yet staged for submission: (Using"git add <file>, ... ."update the content to be submitted) (using"git checkout--<file>, ... ."Discard workspace changes) Modified: README.MD modification has not yet joined the commit (using"git add"and/or"git commit-a") [email protected]:~/joe/testgit/git-test$
git add readme.md
// Add [Email protected]:~/joe/testgit/git-test$ git status 'origin/master' consistent . Changes to commit : "git reset HEAD <file> " withdrawal staging area) modified: readme.md[email protected]:
git commit-m "test"
// Submit 1file1 insertion (+) [email protected]:~/joe/testgit/git-test$ git Status in Branch master
'origin/master' total 1
a commit. The inconsistent "git push" will be displayed only after submission to Publish your local commit) No file to submit, clean workspace [email Protected]:~/joe/testgit/git-git push Origin master// push
Object Count:3, complete. Write to the object: -% (3/3),261bytes |0bytes/s, complete. Total3(Delta0), reused0(Delta0) to [email protected]:joesgit15/git-test.git 111509c.. c287068 Master-Master[email protected]:~/joe/testgit/git-test$ git status in branch master your branch and upstream branch'Origin/master'consistent. No files to submit, clean workspace
Git learning Notes (4)--Add remote repositories, clone remote libraries, and library push