Git remove a file from a branch, keep it in the master

If you want to keep tracking myfile.txt on master but deleted from mybranch, then you simply need to delete it and commit the delete.

git checkout -b mybranch
rm myfile.txt
git commit -am "delete myfile.txt"

Now when you checkout master, you’ll see your file returned and when you checkout mybranch it will be gone again.

Note that if you merge mybranch into master, it will be deleted on master then too.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)