Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git : give me the repo, nuke everything local, I don't care

Tags:

git

Does git have any pull/checkout 'nuclear option' to get the repo? I don't care about any conflicts, I don't need any of my local stuff, just want the goods so I can work.

[edit] to clarify my issues:

$ git pull
error: Your local changes to the following files would be overwritten by merge:

<...files I couldn't care less about...>

Please, commit your changes or stash them before you can merge.
error: The following untracked working tree files would be overwritten by merge:

<...more files I couldn't care less about...>
like image 515
Logan Bender Avatar asked May 14 '13 16:05

Logan Bender


People also ask

How do I override local changes in git?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.

How do I overwrite untracked files in git?

git fetch downloads the latest from remote without trying to merge or rebase anything. git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master .


3 Answers

Better for you to understand the various git commands then to just find the one you need "right now" as you will come up with this situation many times and just learn piecemeal while grumbling and blaming git.

EDIT: I went ahead and tried all the options and this should do it. Thanks to pauljz in the comments.

git clean -df # remove untracked files AND directories
git reset HEAD --hard # revert any uncommitted changes

The above should be all you need.

Other options:

git pull -f # replace local files even if you have unpushed commits.

or

git reset HEAD --hard # remove unchanged, uncommitted files
git pull

or

git clean -f # remove untracked files (uncommitted files)
git pull
like image 64
Mauvis Ledford Avatar answered Oct 16 '22 13:10

Mauvis Ledford


Sometimes the steps listed in the other answers don't work, because [rant redacted]. In that case, your "tactical nuke" option is to:

(If necessary) reset uncommitted local changes so you can switch:

git reset --hard HEAD

Create and switch to a different local branch:

git checkout -b tempBranch

Force delete the (local copy of the) branch with the issues:

git branch -D targetBranch

Checkout and switch to a clean copy of the target branch from remote:

git checkout -b targetBranch origin/targetBranch

Clean up by deleting the temporary local branch you made:

git branch -D tempBranch

If that doesn't work, the "strategic nuke" option is to delete the repo and clone it again.

like image 4
Tom Warner Avatar answered Oct 16 '22 13:10

Tom Warner


You could always delete the entire folder of your existing repo, and then create a new one with git clone

like image 3
Klas Mellbourn Avatar answered Oct 16 '22 12:10

Klas Mellbourn