Reputation: 1841
I know this question has been asked but I can't seem to completely replace my local branch with my remote branch. I had installed a 3rd party plugin in my local branch and am having trouble removing the installation; thus, I want to "start over" with the remote version of the branch. The branch is called "dev" locally and "origin/dev" remotely. I've tried three ways of replacing my local branch with the remote version:
1. git reset HEAD --hard
2. git reset --hard origin/dev
3. git checkout dev
git fetch
git reset --hard origin/dev
But reviewing the local code after the executing the above git commands, I can still see leftover files and folders from the plugin.
Using git status
, I get "Your branch is up-to-date with 'origin/dev'. Nothing to commit, working directory clean".
Using git status --ignored
, I get too many files to list... basically everything in my .gitignore file I believe.
I only want the code that exists in the remote dev branch and nothing else.
Can somebody help?
Update:
Turns out that the error that I was getting was due to a bunch of files in the directory, root/var/cache/*
. My .gitignore
file contains the following entries:
/var/*
!/var/package
var/session/*
Trying the possible ways to restore the local dev branch from remote (listed in the question above as well as the proposed solutions below), the root/var/cache
directory remained present; I had to manually delete it before my application started functioning again. Looking at the github, the remote dev branch did not contain 'root/var/cache. Can anybody tell me why
root/var/cache` was not responding to the git commands for replacing the local branch with the remote version?
Upvotes: 6
Views: 3689
Reputation: 2993
From another branch (say master), reset your dev branch:
git branch -f dev origin/dev
Then, checkout dev and clean up your extra files:
git checkout dev
git clean -d -f
Upvotes: 6
Reputation: 1292
Try git clean -fx
. That will remove all untracked files, even if they're mentioned in .gitignore
.
Upvotes: 4