Exclude file from tracking

In master branch added new file .gitignore and line with *.o Changed to second branch used git pull created file test.o used git status it says, that test.o is untracked and I can add this using git add test.o. Why does that happen? I though test.o will be ignored letting me use git add .

Git does not look if there is a .gitignore file in the  master branch, it just looks if there is a .gitignore file in  your current branch. Make sure you have the .gitignore file in the current branch as well - it is treated by Git as a normal file so isn’t there anymore if you switch to a branch that does not have the .gitignore file.