Connection and use of Git and Github

Connection and use of Git and Github

Foreplay: Git installation

windows: 

https://www.cnblogs.com/kermitjam/p/9404340.html
mac:
mac comes with git client. If it is not installed, you can install it through homebrew git command.

1. Sign up for Github account and create project.

To use git to upload a project to GitHub, you need to have a GitHub account first. If you don't register, you need to register first. Address: https://github.com/login if you don't have a warehouse, you need to create a new warehouse first.

Create warehouse: fill in the new warehouse name and remark information. Click create to finish.

After creation, the following interface will be displayed. It is not necessary to place it first. It will be used later!

Two Git command operations

The transmission between the local Git warehouse and GitHub warehouse is encrypted through "SSH". GitHub needs to identify whether it is your push. As long as GitHub knows your public key, it can confirm that only you can push. Therefore, ssh key needs to be configured.

1. Initialize git

# Create a folder as a warehouse first
mkdir git_demo
cd git_demo

# Initialize git in Git demo
git init 

>>> Initialized empty Git repository in D:/git_demo/.git/

2. Create SSH Key.

In the user's home directory (C:\Users\Administrator), check whether there is a. ssh file. If there is, check whether there are two files under the file, i.e. id_rsa and id_rsa.pub. If there are already, go to the next step. If not, open Git Bash, enter the command, and create SSH Key to enter directly.
ssh-keygen -t rsa -C "githu project url.git"

- Enter the path to save the secret key
- Enter password, can not be set
``![Insert picture description here](https://img-blog.csdnimg.cn/2020021117401374.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
##### The above figure shows that the creation is successful. Then go to the user's home directory and find the. ssh folder. There are two files in the folder, id_rsa and id_rsa.pub. These two are the secret key pairs of SSH Key. Id_rsa is the private key, which cannot be disclosed. Id_rsa.pub is the public key, which can be disclosed.
### 3. Assign your ssh key value to the clipboard.
`# Pbcopy < (key storage directory)

pbcopy < /Users/tank/.ssh/id_rsa.pub`
### 4. Add the key value of the clipboard to the SSH setting of github
##### Next, go to GitHub, open the "Account settings" -- "SSH Keys" page, click "Add SSH Key", fill in the Title (write at will), and paste all the contents in the id_rsa.pub file in the Key text box.
![Insert picture description here](https://img-blog.csdnimg.cn/20200211174534192.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
##### 70)
### 5. Verify whether it is successful. Enter the following command in git bash
`
ssh -T git@github.com
`
##### If it is set for the first time, the following interface will appear. Enter yes to agree
![Insert picture description here](https://img-blog.csdnimg.cn/20200211174934241.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 6. Set username and email as follows, because github will record them every time it commit s
`
 //Your GitHub login
git config --global user.name  "name"

 //Your GitHub registration email
git config --global user.email "1562*****660@126.com"
`
![Insert picture description here](https://img-blog.csdnimg.cn/20200211175139176.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 7. Prepare to upload code
##### Drag your project code to the current git? Master folder.
![Insert picture description here](https://img-blog.csdnimg.cn/20200211175259894.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 8. Execute the command git status.
`
git status
`
![Insert picture description here](https://img-blog.csdnimg.cn/20200211175448350.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 9. Update preparation local warehouse code.
##### At this time, you will see all the changes, and then execute git add. Execute the command git commit -m "first update".
`
 git add . 
  git commit -m "First update"
`
### 10. View project SSH address
![Insert picture description here](https://img-blog.csdnimg.cn/20200211175652736.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 11. Start to associate remote warehouse
`
#git remote add origin git@github.com: user name / project name.git 
'''
>>> git remote add origin git@github.com:TankJam/ATM.git
'''

#Note: if the current add warehouse has been submitted, an error will be reported
>>> fatal: remote origin already exists.

#Need to delete before adding
'''
>>> git remote rm origin
>>> git remote add origin git@github.com:TankJam/ATM.git
`

![Insert picture description here](https://img-blog.csdnimg.cn/20200211175840355.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 12. Upload local warehouse to GitHub
##### Push all the content commands of the master branch for the first time. After each local submission, you can use the command git push origin master to push the latest changes
`
>>> git push -u origin master
`
![Insert picture description here](https://img-blog.csdnimg.cn/20200211180024206.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTM0OTA5,size_16,color_FFFFFF,t_70)
### 13. Pay attention to the pit!
##### Problems caused by creating readme when creating a warehouse
![Insert picture description here](https://img-blog.csdnimg.cn/20200211180111806.png)

## GitHub in pycham 
	[](https://www.cnblogs.com/kermitjam/p/9404047.html)
## Four original articles
[Add link description](https://www.cnblogs.com/kermitjam/p/10697185.html)
Published 2 original articles, praised 0, visited 26
Private letter follow

Tags: git github ssh Mac

Posted on Tue, 11 Feb 2020 05:21:32 -0500 by earthlingzed