Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

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.

1 Answer

+3 votes
by (27.5k points)

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

by (29.3k points)
Awesome! Great answer.

Browse Categories

...