Remove commited file from git repo keeping local copy

James Bhatta
Dec 21, 2020

--

  • Create a .gitignore if you have not one already
  • Edit .gitignore and add the path/to/file
  • Execute git -rm --cached path/to/file . All the removed files will be listed. The --cached file specifies that you want to remove it from repository but keep the local copy. Also you can use -r flag to remove files recursively.c
  • Run git-status to verify the changes.
  • Push the code to repository using git push.

Note: while you ignored those files from repository, they can still be viewed from history. Thus if you want them to be excluded from history as well, make sure you remove them from Git History.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

James Bhatta
James Bhatta

Written by James Bhatta

Manoj Bhatta. PHP developer often working in Laravel. Loved PHP just because I cant wait until compiler processes my code.

No responses yet

Write a response