Reset And Sync Local Repository With Remote Branch - Git - OCPsoft
Maybe your like
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 Or step-by-step: git fetch origin git reset --hard origin/master git clean -f -d Your local branch is now an exact copy (commits and all) of the remote branch.
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$
Submitted by George Gastaldi
13 Comments
-
George Gastaldi says: September 22, 2012 at 11:22 am
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:
git resetupstreamor
git resetorigin [reply] -
Warwick says: November 5, 2014 at 8:52 pm
Brilliant
Thank you
[reply] -
Dana says: March 18, 2015 at 5:34 pm
Thanks a ton. You save my life (almost) with this.
[reply] -
Battaile Fauber says: January 3, 2016 at 8:44 am
Awesome, thanks! Thought I was going to have to start my local version over from scratch after getting out of sync.
[reply] -
Cat says: April 12, 2017 at 9:51 am
Thank you thank you for posting this! I’ve been looking through Stack Exchange for hours, but this is exactly what I needed and it worked perfectly!
[reply] - Need to reset git branch to origin version – Read For Learn says: October 19, 2021 at 12:32 pm
[…] blog post suggests those aliases (for master branch only, but you can adapt/extend […]
[reply] - Everyday GIT - Aditya Tyagi says: January 8, 2022 at 4:59 am
[…] git fetch origin && git reset –hard origin/master && git clean -f -dReference 1 […]
[reply] - "Yerel depoyu uzaktan dalı ile sıfırlayın ve senkronize edin" kodu Cevap - Kod Yanıtları says: February 16, 2022 at 10:13 pm
[…] Kaynak shell shell […]
[reply] - Need to reset git branch to origin version – Code D3 says: August 25, 2022 at 8:23 am
[…] blog post suggests those aliases (for master branch only, but you can adapt/extend […]
[reply] - Need to reset git branch to origin version – Row Coding says: September 4, 2022 at 1:53 pm
[…] blog post suggests those aliases (for master branch only, but you can adapt/extend […]
[reply] - Need to reset git branch to origin version – Tech Help Notes says: September 6, 2022 at 1:05 am
[…] blog post suggests those aliases (for master branch only, but you can adapt/extend […]
[reply] - Need to reset git branch to origin version – w3toppers.com says: October 3, 2022 at 6:29 pm
[…] blog post suggests those aliases (for master branch only, but you can adapt/extend […]
[reply] - Solved: Need to reset git branch to origin version - Daily Developer Blog says: October 13, 2022 at 5:49 am
[…] after the reset would ensure a working tree exactly identical to the branch you just reset to. This blog post suggests those aliases (for master branch only, but you can adapt/extend […]
[reply]
Leave a Comment
Click here to cancel reply.Name
Mail (will not be published)
Website
Please note: In order to submit code or special characters, wrap it in [code lang="xml"][/code] (for your language) - or your tags will be eaten.
Please note: Comment moderation is enabled and may delay your comment from appearing. There is no need to resubmit your comment.
Do you play Magic?
Get TopDecked MTG, the #1 Magic App, built by players, for players. Free to use, forever.- Deck Builder
- Deck Simulator (3d)
- Collection management
- Cards & Prices
- Recent Articles
- Top 8 Decks & Metagame
- Trading Tools
- Commander-friendly

Get updates from OCPSoft
Sign up to receive our free newsletter - new features, new projects, and enhancements to OCPsoft itself. (We respect your privacy.)If you find our tools useful, please consider making a donation to help us stay online and building software!
Shameless Advertising
Read Something New
- PrettyTime 5.0.0.Final Released – New APIs, JDK 8 DateTime support
- Appium: Running the same suite across multiple OSes
- Flakiness of Corporate Selenium Suites and how to get rid of it
- Rewrite 3.4.0.Final Release Announcement
- SEO-friendly AngularJS with HTML5 pushState(), Rewrite, and twelve lines of code
Shameless Advertising
Search Articles
Tag » How To Reset Git Origin
-
Git Reset Origin – How To Reset A Local Branch To Remote Tracking ...
-
Git Reset To Remote Head – How To Reset A Remote Branch To Origin
-
How To Reset A Git Branch To A Remote Repository
-
Git, How To Reset Origin/master To A Commit? - Stack Overflow
-
How To Change Git Remote Origin - Devconnected
-
How To Reset Remote Origin Git Code Example - Code Grepper
-
Git And GitHub: How To Hard Reset Local And Remote Repository
-
How To Reset GIT To Origin/master? - Maslosoft
-
Git Reset Origin To Commit - Christian Engvall
-
Git Reset To Remote - Linux Hint
-
Reset Master To Match Remote - 30 Seconds Of Code
-
Managing Remote Repositories - GitHub Docs
-
Git Reset Local Branch To Remote - Linux Hint
-
Git Reset | Atlassian Git Tutorial