Home > Mobile >  Remove branch files without removing one by one git
Remove branch files without removing one by one git

Time:10-28

I am new to Git, I created a repository and in it I made 2 branches, one master and another test, the master branch contains the following:

File1.php
File2.php

And the test branch contains the following:

File3.php
File4.php

If I do a pull from the test branch, it downloads the branch corresponding files, but I want remove them once I don't need the branch in the local repository. Is there a way to remove the files just choosing the branch to remove and not removing them one by one?

Example of what I want: git branch -d test --remove-files so Git deletes the branch and the files that belong to that branch.

CodePudding user response:

To remove a file both from the Git repository and the filesystem, you can use git rm without any parameters (except for the file's name, of course)

git rm file1 file2 

If you only want to remove the file from the repository, but keep it on the filesystem, you can add the --cached flag:

git rm file1 file2 --cached

CodePudding user response:

From my knowledge, you have to select the files manually.

This will remove the file from your local repo.

git rm "file.ext"

IF you pushed to your remote repo and want to remove it from there too then this is the command you need to remove the files from your remote repo.

git rm "file.ext" --cached

IF you have a directory containing all the files you want to delete you can do the following command to remove the directory and all the files contained within it

rm -r "folder-name"

Delete the branch locally.

git branch -d "branch-name"

Delete the branch on the remote side.

git push origin --delete "branch-name"

CodePudding user response:

  1. Delete a branch LOCALLY: git branch -d branchname
  2. Delete a branch REMOTELY: git push origin --delete branchname
  3. See this link for the answer to your question: How do I delete a Git branch locally and remotely?
  •  Tags:  
  • git
  • Related