树莓派 安装 git 2022-05-27

先检查版本,一般系统都自带了 Git, 如果没有再安装

pi@pi:~ $ git --version
git version 2.20.1
pi@pi:~ $

安装 Git

pi@pi:~ $sudo apt install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
git is already the newest version (1:2.20.1-2+deb10u3).
0 upgraded, 0 newly installed, 0 to remove and 331 not upgraded.
pi@pi:~

升级Git 重新安装会自动升级

pi@pi:~ $sudo apt install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
git is already the newest version (1:2.20.1-2+deb10u3).
0 upgraded, 0 newly installed, 0 to remove and 331 not upgraded.
pi@pi:~

配置Git

自己注册一个Github账户然后
用户名 替换成你自己的
用户名@example.com 替换成注册Github时填写的邮箱。

git config --globaluser.name "用户名"
git config --globaluser.email "用户名@example.com"

参看全局配置 ls -la


image.png
image.png

这里已经可以下载代码了。

git clone -b master https://github.com/micropython/micropython.git
cd micropython
git submodule update --init -- lib/pico-sdk lib/tinyusb
cd lib/pico-sdk 
git submodule update --init lib/tinyusb
sudo apt update
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential
cd ../../mpy-cross
make

生成 ssh 公钥 私钥:

ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"

pi@pi:~ $ ssh-keygen -t ed25500 -C "[email protected]"
Generating public/private ed25500 key pair.
Enter file in which to save the key (/home/pi/.ssh/id_ed25500):
Created directory '/home/pi/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/pi/.ssh/id_ed25500.
Your public key has been saved in /home/pi/.ssh/id_ed25500.pub.
The key fingerprint is:
SHA256:whGVxxxxxxxxx
The key's randomart image is:
+--[ED25519 256]--+
|      .++=..o..  |
|      oo* o. .E  |
|         o..o.   |
+----[SHA256]-----+
pi@pi:~ $

将私钥上传到GitHub, 切记私钥public key

Git 基本命令

git clone 把 github 上的仓库克隆到本地。
git pull 把 github 上的同步到本地仓库。
git push 同步云端仓库
git status 命令用于查看项目的当前状态
git add 命令将该文件添加到缓存
git commit -m "注释"命令将add过的内容提交到本地仓库,并添加一些注释

解决 GitHub 部分访问问题

查询GitHub最新IP
https://ipaddress.com/website/github.com

image.png

打开Hosts

sudo nano /etc/hosts

在最后加入一行,也可以加入多行

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

140.82.112.4    github.com
140.82.113.4    github.com

按Ctrl+X, 按Y保存退出


image.png

参考

https://zhuanlan.zhihu.com/p/112112207
https://www.cnblogs.com/TF511/articles/10645857.html

你可能感兴趣的:(树莓派 安装 git 2022-05-27)