Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git
branch
remote
reset
repository

How to reset a Git branch to a remote repository

Educative Answers Team

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
    
svg viewer

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.

RELATED TAGS

git
branch
remote
reset
repository
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring