1

I create a new repo and want to push my project. But I have some files like a config.js. I want to push config.js once. I already push it, add config.js to .gitignore, but changing of config.js putting to commit. How I can push it once?

.gitignore:

node_modules/
DB/
sessions/

git status

git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore
        modified:   DB/DB.js
        modified:   DB/pg.js
        modified:   app.js
        modified:   policies.js
        modified:   rights.js
        deleted:    sessions/ed83156281f80feb08ede1b087d0a91bd34e78eca8f210d4c0a0b8b8c1b50390.ses

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        rightsDict.js

Why my folder DB in list?

Andrey Kadnikov
  • 455
  • 5
  • 13
  • if you see config.js among your unstaged files, ready to commit, so you have bad configured the .gitignore – Lorenzo Isidori Aug 20 '19 at 07:07
  • updated(add contain files) – Andrey Kadnikov Aug 20 '19 at 07:33
  • it seems all ok. Have you others .gitignore in others path who override whose rules? Are you sure your .gitignore is in the same directory level of DB folder (it seems to be, but I ask again). Have you tried to add a * after DB (DB/*)? – Lorenzo Isidori Aug 20 '19 at 08:25
  • ls -a `. .. .git .gitignore DB` – Andrey Kadnikov Aug 20 '19 at 09:30
  • 1
    The reason you have `DB` in your `status` list is because you (most probably) staged that directory at some point and then added it to your `gitignore`. Do you want git to stop tracking your `DB` folder? If you want to push a file once, then stop git from tracking it again, then you need to do the following: `git rm --cached ` or `git rm -r --cached ` for folders. Check [this out](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – mnestorov Aug 20 '19 at 11:05

1 Answers1

1

Before cleaning up your repository, you should conduct two important preparations:

  • Make sure your .gitignore file is up-to-date and contains all the correct patterns you want to ignore.

  • Commit or stash any outstanding local changes you might have. Your working copy should be clean before you continue.

    $ git rm -r --cached .                                                    
    $ git add .
    $ git commit -m "Clean up ignored files"
    
Abdulhaq Shah
  • 542
  • 2
  • 15