How to replace local with remote branch entirely in Git?

1.5K    Asked by RishabhDwivedi in Data Science , Asked on Jul 12, 2021

I have two branches:

  1. local branch (the one which I work with)

  2. remote branch (public, only well-tested commits go there)

Recently I seriously messed up my local branch.

How would I replace the local branch entirely with the remote one, so I can continue my work from where the remote branch is now?

I have already searched and checked out to the remote branch locally does not have any effect. How git replace local with remote?

Steps required to replace local with remote:




Step 1: Delete your local branch

    $ git branch -d local_branch

Step 2: Fetch the latest remote branch

    $ git fetch origin remote_branch

Step 3: Rebuild the local branch based on the remote one

$ git checkout -b local_branch origin/remote_branch

Your Answer

Interviews

Parent Categories