Skip to content

How to synchronize local repository with the latest version on Github

Greg Wong edited this page Sep 16, 2017 · 5 revisions

Warning: Keep a local copy of your current version or commit it to your personal repository as this method will overwrite all files in your local repository.


Whether you are using Github desktop or git, if you ever come across situations where you cannot fetch the origin as the files were updated (e.g., you are working on your-branch-1 and origin/your-branch-1 has been changed), here is a simple method you can use if you simply want to get the latest files from any branch in your Github repository without saving your local changes.

Sample error message with git checkout on Mac Terminal

Steps to replace all local files

  1. Install Git on your computer
  2. Go to the directory of the Github folder
  3. Run the following command: git reset --hard HEAD
  4. Now, you will have the latest files downloaded from your branch on Github. All the old files are overwritten.

Reference: Screen capture of the above steps with Linux Terminal

  • Sample repository name: FreeCodeCampHongKong.github.io