How To Reset A Git Branch To A Remote Repository

ExploreEXPLORE THE CATALOGSupercharge your career with 700+ hands-on coursesView All CoursesPythonJavaJavaScriptCReactDockerVue JSRWeb DevDevOpsAWSC#LEARNING TOOLSExplore the industry's most complete learning platformCoursesLevel up your skillsSkill PathsAchieve learning goalsProjectsBuild real-world applicationsMock InterviewsNewAI-Powered interviewsPersonalized PathsGet the right resources for your goalsLEARN TO CODECheck out our beginner friendly courses.PricingFor BusinessResourcesNewsletterCurated insights on AI, Cloud & System DesignBlogFor developers, By developersFree CheatsheetsDownload handy guides for tech topicsAnswersTrusted answers to developer questionsGamesSharpen your skills with daily challengesSearchCoursesLog InJoin for freeHow to reset a Git branch to a remote repository

A Git branch can be reset to exactly match the remote branch with the following commands:

  1. Save the state of your current branch in another branch, named my-backup,in case something goes wrong:

    git commit -a -m "Backup." git branch my-backup
  2. Fetch the remote branch and set your branch to match it:

    git fetch origin git reset --hard origin/master

This example assumes that the remote repo’s name is “origin” and that the branch named “master”, ​in the remote repo, matches the currently checked-out branch in your local repo.

Relevant Answers

Explore Courses

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved

Tag » How To Reset Git Origin