How to keep .gitignored files off my gh-pages branch?

In my global .gitignore file I chose to keep my IDE folders out of my versioning. So in my master branch are folders like .idea/ or *.iml files. If I now switch to branch gh-pages git keeps those IDE specific files and I’m ending up with /index.html, /src/.idea/, /sample/.idea/ on that branch even though I don’t want the IDE configuration to appear on gh-pages.

What’s the best way to tell git to drop these files on that branch?

  • code from branch running on master
  • Cloning Git repository throwing ArithmeticException
  • Git pull keeps deleting everything I've added
  • How to modify someone else's Github pull request?
  • How to get branch name in log?
  • Reset changes in git comes back
  • Can't track remote branch - doesn't recognize origin/develop
  • Keeping API keys and access details for the database secure
  • Adding git subtree from a branch
  • Github pulling does not work in - Rails 5
  • Git pushing unfinished changes to repo
  • msysgit error with hooks: “git error: cannot spawn .git/hooks/post-commit: No such file or directory”
  • One Solution collect form web for “How to keep .gitignored files off my gh-pages branch?”

    You probably git added those files before setting up the ignore rules. Ignore rules apply to untracked files only; they have no effect on stuff that’s already staged/committed.

    Given that situation, you can simply make a new commit to get rid of them again:

    git rm --cached <bad files>
    git commit
    

    Or you can use history rewriting to get the unwanted files out of the history altogether. Don’t do this if other people are already working on the current version of your repo, though.

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