• Now that we’ve learned how to time travel a file in Git repository, you don’t have to worry about backups or lost files anymore.
  • However, those who have used SVN, a centralized version control system, will come out and say that these features have been in SVN for a long time, and they don’t see anything special about Git.
  • Yes, Git is no different from SVN when it comes to managing file history in a repository. In order to make sure that what you’re learning about Git is worth it and that you won’t regret it in the future, this chapter introduces one of Git’s killer features to those who have already learned SVN. : Remote repository.
  • Git is a distributed version control system. The same Git repository can be distributed on different machines. How do you distribute it? In the beginning, only one machine must have an original library. Thereafter, other machines can “clone” the original library, and each machine’s library is the same, there is no primary or secondary.
  • You’d think you’d need at least two machines to play remote libraries, right? But I only have one computer. How can I play?
  • In fact, it is also possible to clone multiple version libraries on a single computer, as long as they are not in the same directory. However, in real life, no one would be so stupid as to make several remote libraries on a computer to play, because there is no point in making several remote libraries on a computer, and the hard drive will cause all libraries to die, so I won’t tell you how to clone multiple repositories on a computer.
  • What happens is you get a computer to act as a server, turn it on 24 hours a day, and everyone else clones a copy from the “server” repository onto their own computer, and pushes their own submissions to the server repository, and pulls others’ submissions from the server repository.
  • It is perfectly possible to set up your own Git server, but at this stage, setting up a server to learn Git is a big deal. However, there is a website called GitHub which provides Git repository hosting service, so as long as you register a GitHub account, you can get Git remote repository for free.
  • Before reading more, please register your Own GitHub account. Since transport between your local Git repository and GitHub repository is encrypted over SSH, a few Settings are required:
  • Step 1: Create an SSH Key. In the user’s home directory, see if there are any.sshDirectory, if yes, check to see if there is one in this directoryid_rsaandid_rsa.pubThese two files, if already available, can be skipped to the next step. If not, open the Shell (Git Bash on Windows),Create an SSH Key:
$ ssh-keygen -t rsa -C "[email protected]"
Copy the code
  • You need to change your email address to your own email address, and then press enter and use the default value, because of thisKeyIt’s not for military purposes, so there’s no need for a password.
  • If all goes well, it can be found in the user’s home directory.sshTable of contentsId_rsa and id_rsa. PubTwo files. These are the two filesSSH Key Specifies the Key pair.Id_rsa is the private keyIt can’t get out.Id_rsa.pub is public key“And feel safe telling anyone.
  • Step 2: Log in to GitHub, open “Account Settings”, and “SSH Keys” page:
  • Next, click “Add SSH Key”, fill in any Title and paste the contents of the id_rsa.pub file in the Key text box:

  • Click “Add Key” and you should see the added Key:

  • Why does GitHub need an SSH Key? Because GitHub needs to know that the submission you’re pushing is actually yours, and not someone else’s, and Git supports SSH, GitHub can confirm that only you can push it if you know your public key.
  • Of course, GitHub allows you to add multiple keys. Let’s say you have several computers, and you submit them at work or at home. If you add the Key of each computer to GitHub, you can push to GitHub from each computer.
  • Finally, a free Git repository on GitHub is available to anyone (but only you can change it). So, don’t put sensitive information in there.
  • If you don’t want others to see your Git repository, there are two ways to do it. One is to cross the protection line (which is now free) and have GitHub make the public repository private so that no one else can see it (unreadable and even unwritable). Another option is to build your own Git server, which is invisible to others because it is your own Git server. This approach, which we’ll talk about later, is fairly simple and necessary for internal development.
  • Make sure you have a GitHub account and we’ll start learning about remote warehousing.

summary

  • “With remote storage, mom doesn’t have to worry about my hard drive anymore.” – Git point reading machine