
I encountered mis-deletetion when combined with DDEV. Before you do this (if this your first time), make sure that you back up your branch before you reset it in case something goes wrong.
It is worth noting there is also an interative mode ( -interactive) which will ask you about specific files and/or folders. DESCRIPTION In the first three forms, copy entries fromYou can also replace the master branch with whatever branch you want the pull request. git cleanīe aware though, with the (in)correct flags it may remove config files & folders too. You can substitute origin with the remote repository you are pulling from. git reset -hard cedc856 git push -force origin.
gitignored) you can run the following command. Then use git reset hardIf you want to get rid of everything that is not committed (and not. Remove everything in your repository that shouldn't be there Save the Current State of the Local Branch Do a Git Checkout Fetch the Origin Reset the Local Repository Clean up Any Untracked Changes in the. If running this independently then ensure a git fetch is run first. This last one only works correctly as a git fetch origin was run beforehand. Reset your current main branch back to what is on origin git reset -hard origin/main Remove all existing stashes git stash clear There are two commands you can use to achieve this. git branch | grep -invert-match "main" | xargs git branch -deleteĬlean any remote branches your repository thinks it knows about that no longer exist git fetch origin -prune

Replace main with your primary branch name below. the remote branch and set your branch to match it: git fetch origin git reset. We ran through the following commands which got the local repository nice and clean and back to it's original state. A Git branch can be reset to exactly match the remote branch with the. We didn't want to delete the folder again as we use ddev for our local development and doing that would clear out config files - something which can be rebuilt but would be easier if we could avoid it.

I recently had to help a colleague get their local Git repo back to what was on the origin (Github/Gitlab etc.).

Stale branches, people forgetting to push to origin and mixed commits with rebases and cherry-picks are all ingredients for a big fresh pot of what-the-hell with a side of rm -rf. It reverts your working tree back to a past state, but on a new branch, so if you decide to commit your changes against the past state, you wont have altered. With a myriad of branches and developers, Git repositories can quickly get in a muddle.
