Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove all files in my git repo and update/push from my local git repo?

Is it possible to remove all files in a repository and update it with only the files I have in my local machine? The reason is that, there are certain files that is not necessary in my github and so I want to remove those files. Instead of removing the files one by one, I wanted to see if its possible to just remove all files in my git repo and update/push with only the files in my local machine. Hope its clear. Thanks.

like image 982
dchhetri Avatar asked Jan 29 '12 04:01

dchhetri


People also ask

How do I remove all files from a git repository?

In order to delete files recursively on Git, you have to use the “git rm” command with the “-r” option for recursive and specify the list of files to be deleted. This is particularly handy when you need to delete an entire directory or a subset of files inside a directory.


1 Answers

You could do it like this:

cd /tmp git clone /your/local/rep  # make a temp copy cd rep git rm -r *                # delete everything cp -r /your/local/rep/* .  # get only the files you want git add *                  # add them again git status                 # everything but those copied will be removed git commit -a -m 'deleting stuff' cd /your/local/rep git pull /tmp/rep          # now everything else has been removed 

There's probably a oneliner for that…

like image 152
pascal Avatar answered Sep 24 '22 21:09

pascal