You have created a new repository and pull the code from remote to local, normally when you created a project in bitbucket it’s asking to you do some steps.

  1. You want to upload existing site
  2. You want to create a project from scratch.

If you have already git initialize in a project, you must create the .gitingore file in project folder

What is Gitingore:

.Gitingore Tells to git which files it should ignore. It’s usually used to avoid committing unnecessary files from your working directory. You don’t need to commit some files to your project every time. Some of the common .gitingore files are .htaccess, temp, product, config, node_module, and module

Why .gitnore not working :

Setup a remote repository at Github or bitbucket and it asks you whether you want to create a .gitignore file. So now you have a created repository remotely and pull the total remote project files to locally. After setup project in local, some of the files are changed and push to remote but when you pushed code remote .gitingore added files and folder push to remote because the files are already stored in your local commit tree. You need to remove them from the repository.

You have to remove all tracked files and add them back in using the below commands

[php]
git rm -r –cached .
git add .
git commit -m ".gitignore file working and not pushed ignore files to remote"
[/php]

When you run the first command in terminal it will remove all tracked and cached files from git.
The second command tells to add them back to git and the third command tell to commit all tracked, cached and changed files to remote.

Now you can check remote project and see gitingore files and folder removed from your project.

Don’t forget to commit files