在树莓派上部署个人用的Git管理自己的代码

在树莓派服务器端:

apt install git
# 安装完成后在想要用来存储数据的文件夹下执行命令
git init --bare xxx.git
# xxx可以是项目名,到时候本地git clone下来的就是这个文件夹名字
# 因为是自己局域网的,我没设权限,直接暴力给最高权限给文件夹
chmod -R 777 xxx.git

在客户端:

# 先安装 git,地址:https://git-scm.com/downloads 下载好以后安装
# 打开git bash界面
git clone [email protected]:/data/test.git
# 我这里用户名是 pi , 192.158.9.103是 服务器IP地址, /data是存储地址 ,test.git是创建的项目

如下效果:

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp
$ git clone [email protected]:/data/test.git
Cloning into 'test'...
The authenticity of host '192.168.9.103 (192.168.9.103)' can't be established.
ED25519 key fingerprint is SHA256:cdrGuXCGyL9qJO/N0uQXmcq2Mr4U78XBjSaY3aTwe9U.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.9.103' (ED25519) to the list of known hosts.
[email protected]'s password:
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp
$ ls
test/
$ ls test/
myweb.py

可以看到本地多了一个test文件夹,里面又一个我的脚本
进到文件夹内:

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp
$ cd test/

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ git log
commit 287d3516ac65afecaf6cf3dba7d81b35d7f8875d (HEAD -> master, origin/master, origin/HEAD)
Author: xxx <[email protected]>
Date:   Sat Dec 16 15:54:43 2023 +0800

    init first version

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$

可以看到别人的commit
你需要commit 的话,首次commit需要先创建一些信息,如下:

git config --global username "your_name"
git config --global user.email "your email"
# 然后添加本地想要上传的脚本 . 代表文件夹下所有脚本
git add .
# 然后 commit,-m 备注此版本更新的主要信息
git commit -m "备注关键修改信息"
# 可以关联一下远程仓库
git remote add origin [email protected]:/data/test.git
# 推送代码到远程仓库
git push origin master
# 抓取代码
git pull 
# 有时会报错,如果你本地代码修改不想要了,可以直接按如下方式抓取master的
git fetch --all
git reset --hard origin/master
git pull

如例:

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ git config --global user.name "test"

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ git config --global user.email "xxx.qq.com"

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ ls
myweb.py

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ cp myweb.py 1.py

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ git add .

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ git commit -m "test add new script"
[master f9712bb] test add new script
 1 file changed, 52 insertions(+)
 create mode 100644 1.py

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)
$ git push origin master
[email protected]'s password:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 230 bytes | 230.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
To 192.168.9.103:/data/test.git
   287d351..f9712bb  master -> master

ward@DESKTOP-C54246H MINGW64 ~/Desktop/tmp/test (master)

你可能感兴趣的:(杂用工具,Linux系统,git)