Establish a connection between Git and GitHub in Linux, gitgithub
Git is an open-source distributed version control system, while GitHub relies on Git's code hosting platform.
GitHub uses Git's extremely powerful clone and Branch functions to allow community members to freely participate in open-source projects.
However, before you start learning, you need a GitHub account and a Linux virtual machine that can be connected to the Internet.
1. Install Git
* If you have installed Git, skip this step.
Install Git in Ubuntu: apt-getinstall git
CentOS install Git: yum install git
View Git version: git version
Configure Git user information:
git config --global user.name "woider" git config --global user.email "woider@gmail.com"
↑ Replace the user name and email address with your own. If no output is displayed after you type the command, the setting is successful.
Ii. Enable the SSH service
* If you are using CentOS, SSH is enabled by default. skip this step.
Install SSH on Ubuntu: apt-getinstall ssh
View SSH service status: ps-e | grep sshd
Ipvsshd indicates that the ssh-server has been started.
3. generate an SSH KEY
* Use ls-al ~ /. Run the ssh command to check whether the ssh key exists. If yes, ignore this step.
Generate an ssh key: ssh-keygen-t rsa-C "woider@gmail.com"
In the process of generating an ssh key from the keystore, you will be asked to enter passphrase and press enter three times to skip it.
=================== Ssh key ====================================
1. view the SSH KEY
Go to the/root/. ssh directory and view the id_rsa and id_rsa.pub files:
root@localhost:~# cd /root/.ssh root@localhost:~/.ssh# ls -a
↑ Id_rsa is the private key and id_rsa.pub is the public key.
Ii. Copy the SSH KEY
Open the id_rsa.pub file and copy the content to the clipboard: vim id_rsa.pub
Secret ssh key public KEY for GitHub Authentication
3. Add an SSH KEY
Log on to GitHub, open the Personal settings page, and select the SSH and GPG keys option:
You can enter the license Title at will, and enter the content you just copied from id_rsa.pub in the Key.
After the SSH key is added, Linux can establish a connection between local Git and GitHub through SSH.
====================== GitHub ==================================
1. Create a GitHub Repository
Creating a repository named baidu
Your SSH address is git@github.com: woider/baidu. git
2. Clone the repository to a local device
Clone the GitHub repository to a local location using the SSH address:
git clone git@github.com:woider/baidu.git
During the first connection, you need to confirm whether the fingerprint information of the GitHub Key is actually from the GitHub server.
Clone to a local repository automatically associates with a remote repository. You can run the git remote-v command to view the association status:
After the slave node is associated, you can use the git push origin master command to push modifications.
Note: If you clone another person's warehouse, you cannot push the modification because you do not have the permission.
/* Create A readme. md file */root @ localhost:/home/baidu # vim readme. md/* output readme. md file content */root @ localhost:/home/baidu # cat readme. md Git associated GitHub ===================/* add the file to the temporary storage zone */root @ localhost:/home/baidu # git add readme. md/* submit this modification */root @ localhost:/home/baidu # git commit-m "add readme file" [master 228d321] add readme file 1 file changed, 2 insertions (+) create mode 100644 readme. md/* push to remote repository */root @ localhost:/home/baidu # git push origin masterCounting objects: 3, done. compressing objects: 100% (2/2), done. writing objects: 100% (3/3), 290 bytes | 0 bytes/s, done. total 3 (delta 0), reused 0 (delta 0) To git@github.com: woider/baidu. git 36c5c1c .. 228d321 master-> masterroot @ localhost:/home/baidu #