Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you remove files from one and only one branch in git

Tags:

git

git-branch

I want a branch to hold all the files from my master branch except for foo.txt and foo2.txt. How do I do this?

like image 571
user678392 Avatar asked Feb 04 '15 21:02

user678392


People also ask

How do I remove a specific file from a remote branch?

Using git rm <deleted-filename> and git add <deleted-filename>. Your branch is up-to-date with 'origin/master'. It will stage the deleted file, and followed by git commit and git push will remove the file from the repository. Your branch is ahead of 'origin/master' by 1 commit.

How do I remove one file from git?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

How do I delete individual files on github?

Browse to the directory in your repository that you want to delete. In the top-right corner, click , then click Delete directory. Review the files you will delete. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.


1 Answers

You have to branch off from master. Check out a new branch and remove the files you do not want.

git checkout master

Once in master:

git checkout -b new_branch

rm foo.txt
rm foo2.txt

git add -u
git commit -m "removed foo and foo2"
git push origin new_branch
like image 147
Joel Avatar answered Nov 15 '22 07:11

Joel