.gitignore not working with fresh repo

I’ve got a brand new git repo which I’ve just checked out. I’ve then made an update to my .gitignore with the following line:

wp-config.php

My git status now reads:

  • HgGit: “invalid-email-address” at GitHub
  • What is the Difference Between Mercurial and Git?
  • Can Gitlab/Gitolite enforce correct username/email
  • git svn fetch: Could not unmemoize function `check_cherry_pick', because it was not memoized to begin with
  • Cannot push to git repository - permission denied
  • git - setting a commit's parent without rebase
  • On branch master
    Your branch is ahead of 'origin/master' by 1 commit.
      (use "git push" to publish your local commits)
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    

    I add and commit this file (locally). I then update the wp-config.php file.

    However, now, when I run git status I get the following:

    On branch master
    Your branch is ahead of 'origin/master' by 2 commits.
      (use "git push" to publish your local commits)
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
            modified:   wp-config.php
    

    I’ve gone through this .gitignore is not working
    but the points made don’t seem to be applicable as I’m using a completely fresh repo.

    Any further suggestions?

    Surely I don’t have to commit it to the remote (‘origin/master’) to ignore it locally?

  • How to avoid “Merge branch 'master' of ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm”
  • Send merge conflicts to collaborators to resolve in Git
  • Multiple Docker images in .gitlab-ci.yml
  • Is it safe to interrupt a dcommit call that appears to be hung up?
  • git revert <hash> not allowed due to a merge but no -m option was given
  • Git warning: unable to access 'P:\/.gitconfig': Invalid argument
  • 2 Solutions collect form web for “.gitignore not working with fresh repo”

    Looks like git is already tracking that file, so .gitignore is not working.

    You can just stop git from tracking it with:

    git rm --cached wp-config.php
    

    After that you shouldn’t see wp-config.php in the git status output.

    If the file is already being tracked by git, you need to remove it after you add it to the .gitignore. This will prevent it from being tracked further:

    git rm --cached wp-config.php

    Git Baby is a git and github fan, let's start git clone.