This is my first day of the August Challenge, and it’s a tutorial documenting how to connect your local Git to a remote Github repository. After the setting is successful, you can obtain the code from the remote repository and push the local code to the remote end.
The preparatory work
- Apply for a Github account
- Basic Git syntax
- The Git bash runtime has been installed locally
Set up remote warehouse
After logging in to Github account, click the plus sign in the upper right corner to set up your own repository, name yourself.
Here, test is used as an example.
Configure the SSH key
Creating an SSH key
Execute the command in Git bash:
Ssh-keygen -t rsa -c "[email protected]Copy the code
If there is no special need, you can not set the password and press enter twice to continue.
~/vvd_git$ ssh-keygen -t rsa -C "[email protected]" Generating public/private rsa key pair. Enter file in which to save the key (/home/zywvvd/.ssh/id_rsa): Created directory '/home/zywvvd/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/zywvvd/.ssh/id_rsa. Your public key has been saved in /home/zywvvd/.ssh/id_rsa.pub. The key fingerprint is: SHA256:klt1J9JxcGBj7xgB5dC1cXsQmK9ioOhInLRgqKppO8k [email protected] The key's randomart image is: +---[RSA 2048]----+ | o+p+=o+. | | B.Bo+ o | | = *.+ . . | |. o = *. . | |oo . . u.. * +. | |. | | + *. . . | |*E . . . | |Ooo | +----[SHA256]-----+Copy the code
Output similar to the above is a success. The resulting file is placed in the ~/.ssh folder.
Set up a lot
- Log in making
- Set ‘SSH and GPG keys’ in Settings
- Add new SSH Key – set the name and copy the contents of the isa.pub public key file in the.ssh folder
Test the SSH key
Execute command:
ssh -T [email protected]
Copy the code
Output results:
Warning: Permanently added the RSA host key for IP address '52.74.223.139' to the list of known hosts. You've successfully authenticated, but GitHub does not provide shell access.Copy the code
If the welcome field is displayed, the SSH key is configured successfully.
test
Synchronize a local library to a remote library
Link to an existing local repository using the remote command:
git remote add origin https://github.com/zywvvd/test.git
Copy the code
Edit local library content and push to remote end:
echo "#example" >> README.md
git add README.md
git commit -m "README.md created"
git push -u origin master
Copy the code
You can see the update file on Github.
Cloning of warehouse
Run the following command to create a clone of the local repository:
git clone /path/to/repository
Copy the code
If the repository is on a remote server, your command would look like this:
git clone username@host:/path/to/repository
Copy the code