preface
In Git series 1, we have seen how to manage files locally, including version rollback, undoing some changes, deleting files, and creating a version library. But these only stay in local files. Git is a distributed version control system that can distribute a Git repository across different machines, so we need a remote repository to host our files. Here we use GitHub to help us host the repository so that different users can clone, submit changes, and merge through the repository. To get started, you’ll need to have a GitHub account before continuing.
Add the SSH Key
-
Create an SSH Key. Go to the main directory (C:\Users\ zj-orphke) and check whether there is an. SSH directory. If so, go to the next step. If not, open Git Bash and run the ssh-keygen -t rsa -c “[email protected]” command to generate an SSH Key. Note that the email address above should be yours. Then press Enter, and when the operation is complete, the.ssh directory will appear.
-
If there is no error, the.ssh directory will have two files as follows:
These two are the secret Key pairs of SSH keys. Id_rsa is the private Key and cannot be leaked, and ID_rsa. pub is the public Key.
-
The loginGitHubClick in the order shown below
Fill in the name of the key on the title and copy the contents of the id_RSA. pub file and paste it into the key box below. Finally, hit Add SSH key and you’re done.
Adding remote Libraries
We created a local repository firstGit, now we need to create a Git repository on GitHub and connect the two repositories remotely.
Clicking New will take you to the repository creation page.Fill in the Repository name with the Git Repository name (gitRepository is mine). Click the Create Repository button. So now that we have two repositories ready, the next step is to associate the local repository with the remote repository.
Associate two repositories
Run the command at local Git Bash
git remote add origin https://github.com/zdjzpg/gitRepository.git
Copy the code
Note that the command needs to be filled in according to their own warehouse name, you can also see the following prompt after the new warehouse, directly copy can be. The next step is to push all the content from the local repository to the GitHub remote repository. The command is as follows:
git push -u origin master
Copy the code
Clone from a remote repository
The previous section described creating a remote library from a local library, but it is also possible to clone a new local library from an existing remote library. Start Git Bash by right-clicking on your local file and then entering the command
git clone [email protected]:michaelliao/gitskills.git
Copy the code
Note that this address is also your GitHub repository, so you can copy a copy of the latest data and files from the remote repository to the local repository, and also naturally many people to control a repository. But the problem comes, for example, if you change this line, AND I change this line, the warehouse will end up with a conflict between you and me. Of course there are problems and there will be solutions. In the next post, I’ll try to show you how to control these branches.