What is wrong with my .gitignore

I’m trying to exclude my zones.yaml, but it keeps getting uploaded. This is my first time dealing with this. I can delete it of course, but it still in the history,

*
!*.yaml
!scenes
!packages
!.gitignore
secrets.yaml
known_devices.yaml
zones.yaml

secrets and known_devices dont get uploaded, but zones.yaml does. :frowning:
Also if you can tell me an easy way to remove it from history that would be great too. Otherwise I’ll get the ignore file working, and just delete and start over since I just started.

You’re better off deleting it [repository] and starting over if you just started since the file is still in history.

Remember to use the path so if it’s in another file than the .homeassistant root then it won’t work.

I i did delete and the zoness file got uploaded again.

is zones.yaml in your root directory? For your .gitignore just add the files you want to ignore. if you must just manually each file you want to upload.

it is in my root, and my .gitignore is posted above, it’s in the same path as my secrets.yaml and that is not being uploaded

Are you removing remote and local repository?

thanks, that did it. Also just to be safe before I did it this time, Just went ahead and added all my zone info (lat/long) to my secrets file anyway. I had it in my configuration.yaml too.

Thanks for the help

glad you got it working. I know it can be frustrating when you start out. I had the same issues trying to figure out ignores as well.

I got it working, but am still confused. If I want to include more items in my git, for example I just added a folder to my .gitignore

!foldername

I then did

git add .
git status
echo -n "Enter the Description for the Change: " [Minor Update]
read CHANGE_MSG
git commit -m "${CHANGE_MSG}"
git push origin master

but the folder never got committed.

I’m sure this is just git 101, just not sure what I need to do to make it “relook” at my ignore file

If you’re trying to add files just add them. use your .gitignore only for ignoring files.

ie, here’s mine for example. it only lists the things I want to ignore

.cloud
.config_entries.json
deps/
gactions
home-assistant.log
home-assistant_v2.db
html5_push_registrations.conf
.ignore
includes/zones
known_devices.yaml
options.xml
OZW_Log.txt
phue-001788290cbf.conf
pyozw.sqlite
secrets.yaml
tts/
zwcfg_0xe32a7bcc.xml
zwscene.xml
www/
.shopping_list.json

mta: I see what you’re doing wrt this page
https://git-scm.com/docs/gitignore

you need to make sure you’re using / for paths

So, got it. In my case I did not “Add” anything. I just realized I wanted to include some files/folders that were not part of my initial commit.

*
!*.yaml
!scenes
!packages
!.gitignore
secrets.yaml
known_devices.yaml
zones.yaml

this is what I had

and my git repository has all the yaml files (other than the excluded) and one folder “Packages”. I dont have a scenes folder locally, so that’s not there. coming soon. :slight_smile:

I now want to include a folder that already exists. How would I do that. I think I understand now, that if I add a new file or folder, it will be added automatically, but anything exisiting when I did my first commit wont.

git add /path/ commit and push

Thank you for your help.

Sorry to keep bugging you. Now that I’ve finally set this up, I see how awesome it can and will be.

But also possible for a NOOB like me to erase things (I accidentlly deleted my zones.yaml locally when trying to figure out things, haha), so my question is now about pulls

If I modify a file on github, and then do a pull from my HA server, will it only update the files that are in the repoistiry that have changed, and leave the other files alone. Like lets say I have a file that I never added, would it just get ignored, or would it be deleted because it was not in the repoistiry. I guess the same question for folders, etc

Your repository keeps up with what is local and what is remote. If the file never existed in the repository at all git doesn’t even notice it. Push and pulls only update staged/commited files. If you’ve changed a file but haven’t added it or staged it then it will just sit there until you tell git that you want to update it. If you ever want to see what changes you’ve made you can do a quick git diff to see what you’re edited locally that hasn’t been pushed to the repository.

I’m still very new to git myself. I pretty much just use it for the basic backup function and a place to store some arduino code. There’s a lot that it can do that I don’t even understand myself.

I think the biggest problem is that the first line of your gitignore is *, which means ‘ignore everything’.

Then you’re trying to add things back by using exclamation marks and manual adds before commits.

Maybe this will help get your head round it…

Thanks I got my gitignore example almost 100% from here.

That’s a very bad example IMO.

As stated above a gitignore is for files to ignore. Starting the file with ‘ignore everything’ and then trying to add stuff back is counterintuitive and bound to lead to complications later down the line.

I’m new so I don’t know. I “think” that the intent was to reduce the chance of any username/passwords, sh scripts, or anything else in your HA install from being inadvertently uploaded by noob;s like me. :slight_smile:

The example would backup everything needed for the average HA install to be recovered. And I guess that is what the article was really focusing on.

But yea, it only took a few times to realize that it was not enough for me.

Thanks

How do you determine the files that need to be ignored?
I get secrets.yaml but what about OZW_Log.txt or pyozw.sqlite, etc

Is there a comprehensive list of “unsafe” files to commit?
Also are there files that if you don’t backup then the backup will NOT restore your system. For example will pyozw.sqlite rebuild or is that need in the backup?

Looking at the Cookbook examples of peoples github commits they all seem to ignore different things.
This example excludes a huge list of things.

I just want a backup that will work but of course don’t want to save unsafe items.

Perhaps a private repo is a better option?