Skip to main content
Use SO code syntax to have bash highlighting
Source Link
johannchopin
  • 15k
  • 11
  • 64
  • 125

Use git rm.

If you want to remove the file from the Git repository and the filesystem, use:

git rm file1.txt git commit -m "remove file1.txt" 
git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 
git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 
git push origin branch_name 

Use git rm.

If you want to remove the file from the Git repository and the filesystem, use:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 

Use git rm.

If you want to remove the file from the Git repository and the filesystem, use:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 
Made the consequences of the first suggestion immediately clear to help prevent mishaps by amateur git/command line users
Source Link

Use git rm.

If you want to remove the file from the Git repository and the filesystem, use:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 

Use git rm:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 

Use git rm.

If you want to remove the file from the Git repository and the filesystem, use:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 

Use git rm:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 

Use git rm:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt 

And to push changes to remote repo

git push origin branch_name 

Use git rm:

git rm file1.txt git commit -m "remove file1.txt" 

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt git commit -m "remove file1.txt" 

And to push changes to remote repo

git push origin branch_name 
fix link
Source Link
Greg Hewgill
  • 1.0m
  • 192
  • 1.2k
  • 1.3k
Loading
added comment to the answer to complete the answer
Source Link
Loading
added an important point which if not there, can cause people to lose their files
Source Link
Nav
  • 20.8k
  • 28
  • 101
  • 143
Loading
Rollback to Revision 1
Source Link
Greg Hewgill
  • 1.0m
  • 192
  • 1.2k
  • 1.3k
Loading
added 113 characters in body
Source Link
Nabin
  • 11.8k
  • 8
  • 70
  • 103
Loading
Source Link
Greg Hewgill
  • 1.0m
  • 192
  • 1.2k
  • 1.3k
Loading