I accidentally got a repo in a bad state when trying to move a project from using ant to maven. Now, I would like to clear the repo and startover from scratch. Being new to git, I am a little cautious and not sure if I could just checkout then delete all files and folders locally then push to the remote repo or if that was actually a very bad idea. For some reason I'm having a hard time asking the correct questions in google. :D
To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on).
If you want to restart a git repo, nuke the . git directory and do git init add your files/directories and commit.
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.
In order to delete a local GitHub repository, use the “rm -rf” on the “. git” file located at the root of your Git repository. By deleting the “. git” file, you will delete the Github repository but you won't delete the files that are located in your project folder.
Performing a hard reset of the remote repository is quite easy. After you've reset the local repository, simply do a force push with the follow git command: In the example we used above, that git command would look like this:
When a user clones a Git repository from Github using the command git clone <url>, they get a copy of the remote repo on their local computer so that they can work on it on their current working directory where the repo got cloned without directly making changes on the remote repository.
rm -rf <repository_folder>.git With the deletion of the ‘.git’ file, this will delete the.git file that contains a log of the commit history, its information, and also remote repository address from the working directory.
You can reset to a local commit instead of origin/master, but most of the time you’ll be resetting to the state of the remote. However, git reset is usually not enough. Resetting in Git only resets files that are actually tracked by Git. This includes code and resources that receive changes.
Simply remove local .git
directory, remove repo from server (if it is github - do Repo -> setiings -> remove).
Then create new repository on server, and locally do:
git init git remote add origin [email protected]:user/project.git git add . git commit -m "Initial commit" git push -u origin master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With