skip to Main Content

My .gitignore file is this and it is located in my root folder and there 2 files I want it to be untracked by git

Error:

ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp$ git status
On branch development
Your branch is ahead of 'origin/development' by 3 commits.
(use "git push" to publish your local commits)

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified:   Backend/.gitignore

Untracked files:
(use "git add <file>..." to include in what will be committed)
Backend/myenv/
Backend/webBackend/key.json

ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp$

Why it gives me this?

ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp$ git rm --cached Backend/myenv
fatal: pathspec 'Backend/myenv' did not match any files
ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp$ git rm --cached Backend/webBackend/key.json
fatal: pathspec 'Backend/webBackend/key.json' did not match any files
ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp$

When I have this folders and files in the exact location as you can see here:

ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp/Backend$ ls
db.sqlite3  manage.py  myenv  webBackend
ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp/Backend$

ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp/Backend/webBackend$ ls
asgi.py  firebase_config.py  __init__.py  key.json  loginAuthentication.py  __pycache__  settings.py  signUp.py  urls.py  wsgi.py
ubuntu@ubuntu-VirtualBox:~/Desktop/carguys-ccp/Backend/webBackend$

I want to push my backend files without my virtual enviroment and key.json ! Can anybody tell me why i cant push it to bitbucket correctly?

2

Answers


  1. You ask why these commands cause Git to complain:

    git rm --cached Backend/myenv
    git rm --cached Backend/webBackend/key.json
    

    Here’s your answer, in what Git already told you when you said git status:

    Untracked files:
    (use "git add <file>..." to include in what will be committed)
    Backend/myenv/
    Backend/webBackend/key.json
    

    Those two things are untracked, so they cannot be git rm --staged. Saying git rm --staged means remove them from the index. But being untracked means they are not in the index. There is, as Git rightly tells you, nothing by that name to remove.

    If you want them to stay untracked, i.e. not pushed the next time you make a commit and push it, then just do nothing. All is already as you wish.

    If you want them to stay untracked and not be reminded about this fact every time you say git status, add appropriate entries to .gitignore. But this won’t make any difference to their status. They won’t be pushed, whether to add entries to .gitignore or not.

    Login or Signup to reply.
  2. Your files’ history is already in the commit, I suggest

    git reset --soft COMMIT_HASH
    

    To the last commit that doesn’t have these files, and rebuild the commit.

    Or you can use BFG tool

    # change the below to your BFG installed location
    java -jar ~/hw/cabin/bfg-1.14.0.jar -D vmlinux.h
    
    # prune
    git reflog expire --expire=now --all && git gc --prune=now --aggressive
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search