0

There is a tracked file that we do not need anymore. I deleted the file on my local repository. So what are the git commands to write in order for the action to be effective on the remote repository ?

3
  • has deleting the file locally not allowed for staging the deletion for remote?? Commented Aug 4, 2023 at 15:43
  • Are you asking for git push? Commented Aug 4, 2023 at 15:48
  • stackoverflow.com/search?q=%5Bgit%5D+delete+file Commented Aug 4, 2023 at 16:11

1 Answer 1

1

Untrack the file

If you don't want git to track a file you have to can untrack it with

git rm --cached filename 

Then you will need to commit the changes locally with:

git commit 

After that you can push the changes to the remote with:

git push 

Delete the file

If you want to delete a file, simply remove it from the repo.

Add the changes with:

git add -A 

You can check the changes with git status:

On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git restore --staged <file>..." to unstage) deleted: file.md 

Then you can commit your changes with:

git commit -m "Removed the file" 

To push the changes on the remote:

git push 
Sign up to request clarification or add additional context in comments.

5 Comments

my goal is not to untrack the file, but really make the deletion of the file to be passed on at the remote repo : I want the file to be deleted also at the remote repo.
do I have to make a git add deleted_filename before git commit ?
no : git status gives Changes not staged for commit -> deleted : path/to/the/deleted_filename
Add the changes with git add -A
it is git add -A filename but not just git add -A

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.