2024年11月21日星期四 下午7:33:19

git Sharing your configuration on GitHub

2 年 前
#17673 引用

https://diy-smarthome.com/how-to-set-up-git-to-version-control-your-home-assistant-configuration/

系统自带git,无需安装


Sharing your configuration on GitHub

https://community.home-assistant.io/t/sharing-your-configuration-on-github/195144#step-2-creating-gitignore

quick start


Creating Repository on GitHub


# Initialize the Git repo on Raspberry Pi


Installing  Git on Raspberry Pi
Initializing Git on Raspberry Pi
Creating .gitignore




client git push method

客户端有3种提交方式,github.com 对应有3种设置(本文 .https方式)

1.https   https://www.msly.cn/boards/topic/13385/git/page/2#18781

2.ssh  

  https://www.msly.cn/boards/topic/13385/git/page/2#18782
https://diy-smarthome.com/how-to-set-up-git-to-version-control-your-home-assistant-configuration/

3.GitHub Desktop
https://www.iaspnetcore.com/blogpost-5c8eca62fb51d01218b55422-git-

Quick start

First



cd /home/homeassistant20221102/.homeassistant

git init       <-- initialize as a version controlled directory
git config user.email "[email protected]"
git config user.name "msly"
git add .


#  <-- see what files have been modified.You can enter these commands to get a list of the files in your local Git repository and a status of files that have changed but not committed yet.

git ls-files

git status  

git add README.md
git commit -m "first commit"

git remote add origin https://github.com/freemsly/Home-AssistantConfig20221103.git

git branch -M main

git push -u origin main



git remote add origin https://github.com/freemsly/Home-AssistantConfig.git

second



cd /home/homeassistant20221102/.homeassistant





cd /home/homeassistant20221103/.homeassistant
git add .
git commit -m "first commit"
git push -u origin main






https://github.com/settings/profile
https://github.com/settings/apps
https://github.com/settings/tokens




Check that you have git installed.

which git
/usr/bin/git       <-- already installed


Step 1: Installing and Initializing Git on Raspberry Pi





#<-- update your packages
sudo apt update
sudo apt upgrade -y

#<-- install git if needed
sudo apt install git







output

root@raspberrypi:~# sudo apt update
sudo apt upgrade -y
sudo apt install git
命中:1 http://archive.raspberrypi.org/debian stretch InRelease
0
2 年 前
#18749 引用
Step 2: Creating .gitignore

whoami         <-- which user are you logged in as
root

#Make sure you are in the /config directory
cd /home/homeassistant20221102/.homeassistant

pwd
/home/homeassistant20221102/.homeassistant         <-- make sure you are in this directory
vi .gitignore



# Example .gitignore file for your config dir.
# An * ensures that everything will be ignored.
*
# You can whitelist files/folders with !, these will not be ignored.
!*.yaml
!.gitignore
!*.md

# Ignore folders.
.storage
.cloud
.google.token

# Ensure these YAML files are ignored, otherwise your secret data/credentials will leak.
ip_bans.yaml
secrets.yaml
known_devices.yaml


Torbleshooting
git .gitignore 不生效
https://www.cnblogs.com/rainbowk/p/10932322.html

原因
xxx 文件在前面已经被 git 跟踪,在这之后再添加到 .gitignore 中是无效的
解决方法
在 .gitignore 中添加后,清除一下此文件的 git 缓存,git rm -r --cached 文件名, 然后再进行 commit和 push即可。

gitignore中已经标明忽略的文件目录下的文件,git push的时候还会出现在push的目录中,或者用git status查看状态,想要忽略的文件还是显示被追踪状态。
原因是因为在git忽略目录中,新建的文件在git中会有缓存,如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的,
这时候我们就应该先把本地缓存删除,然后再进行git的提交,这样就不会出现忽略的文件了。
  
解决方法: git清除本地缓存(改变成未track状态),然后再提交:
[root@kevin ~]# git rm -r --cached .
[root@kevin ~]# git add .
[root@kevin ~]# git commit -m 'update .gitignore'
[root@kevin ~]# git push -u origin master
0
2 年 前
#18750 引用
Step 3: Preparing your Home Assistant directory for GitHub

Initialize the Git repo



#Initialize this repository with a README

echo "# Home-AssistantConfig" >> README.md  

git init      <- 已初始化空的 Git 仓库于 /home/homeassistant20221103/.homeassistant/.git/

git config user.email "[email protected]"
git config user.name "999"




git add .
git commit -m "first commit"



now you have an initial git repo

git init  

已初始化空的 Git 仓库于 /home/homeassistant20230202/.homeassistant/.git/
root@raspberrypi:/home/homeassistant20230202/.homeassistant#





output

root@raspberrypi:/home/homeassistant20221102/.homeassistant# git commit -m "first commit"
[main 91aa1ce] first commit
102 files changed, 162731 insertions(+)
create mode 100644 .HA_VERSION
create mode 100644 .storage/auth
create mode 100644 .storage/auth_provider.homeassistant
create mode 100644 .storage/core.analytics
create mode 100644 .storage/core.area_registry
create mode 100644 .storage/core.config
create mode 100644 .storage/core.config_entries
create mode 100644 .storage/core.device_registry
create mode 100644 .storage/core.entity_registry
create mode 100644 .storage/core.restore_state
create mode 100644 .storage/core.uuid
0
2 年 前
#18751 引用




Step 3: Creating Repository on GitHub

Click “New Repository ” and give your repository a name/description (Home-AssistantConfig)
0
2 年 前
#18752 引用
/etc/hosts for Debian

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

127.0.1.1    raspberrypi
185.199.108.133 raw.githubusercontent.com
140.82.114.4 github.com


https://www.matterxiaomi.com/boards/topic/20879#28390
0
2 年 前
#18753 引用
1
0
2 年 前
#18754 引用
Step 5: Your initial commit to GitHub

Now we need to “push” our changes to a central server to back them up

Push from Raspberry Pi to Github


git remote add origin https://github.com/freemsly/Home-AssistantConfig.git
git branch -M main
git push -u origin main


You will be asked to enter your GitHub username and password


root@raspberrypi:/home/homeassistant20221102/.homeassistant# git push -u origin main
Username for 'https://github.com':


输入email and token from GitHub setting

token come from github.com


    Settings/ Developer settings /Personal access tokens (classic)  for repo

https://github.com/settings/tokens


Personal access tokens (classic) ->Tokens (classic)


ghp_m7nnRQsr1IVitz22cv3d0

output

枚举对象中: 3, 完成.
对象计数中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 234 字节 | 234.00 KiB/s, 完成.
总共 3(差异 0),复用 0(差异 0),包复用 0
To https://github.com/freemsly/Home-AssistantConfig.git
* [new branch]      main -> main
分支 'main' 设置为跟踪来自 'origin' 的远程分支 'main'。

0
2 年 前
#18755 引用
push

cd /home/homeassistant20221102/.homeassistant


git add .

git status

git co

root@raspberrypi:/home/homeassistant20221102/.homeassistant# git push -u origin main



root@raspberrypi:/home/homeassistant20221102/.homeassistant# git push -u origin main
Username for 'https://github.com': [email protected]
Password for 'https://[email protected]@github.com':
枚举对象中: 117, 完成.
对象计数中: 100% (117/117), 完成.
使用 4 个线程进行压缩
压缩对象中: 100% (110/110), 完成.
写入对象中:  97% (114/117), 30.30 MiB | 2.20 MiB/s
0
2 年 前
#18756 引用
1
0
2 年 前
#18757 引用
1
0