Reset and sync local respository with remote branch
If you have ever gotten to the point where your local git repository is out of sync with your remote, but you just can’t seem to restore things back to normal, then this command is for you.
This git pro-tip will turn your local repository into a mirror image of the remote of your choice. Simply follow these steps to get back to frustration-free development.
This command will destroy any local changes in your current branch. This tip is part of the guide series, Git.
The command:
Remember to replace origin and master with the remote and branch that you want to synchronize with.
git fetch origin && git reset --hard origin/master && git clean -f -d
git fetch origin git reset --hard origin/master git clean -f -d
Command output:
Here is an example of running the command on a local clone of the JBoss Forge git repository.
sharkbook:forge lbaxter$ git fetch origin && git reset --hard origin/master && git clean -f -d HEAD is now at 356cd85 FORGE-680 Removing forge-example-plugin/ Removing plugin-container-api/ Removing plugin-container/ Removing shell/.forge_settings sharkbook:forge lbaxter$
You may also add as an alias in your .gitconfig file:
[alias] resetorigin = !git fetch origin && git reset --hard origin/master && git clean -f -d resetupstream = !git fetch upstream && git reset --hard upstream/master && git clean -f -dThen you can type:
or