Reset a Git branch to a remote repository

Sometimes you may need to reset or discard all of your changes and reset your local branch to be just like the branch on the remote repository. So today we will show you how to reset a Git branch to a remote repository.

Steps to reset a Git branch to a remote repository

  1. Save your current work
  2. Fetch origin branch and set it
  3. Remove untracked files

1. Save your current work

If you want to save the state of your current branch before doing this, you can use the following commands.

2. Fetch origin branch and set it

Now, setting your branch to exactly match the remote branch can be done in two steps.

3. Remove untracked files

Next, we have to use the git clean to remove the untracked files.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! ๐Ÿ™‚

If you found value in this article,
you can support us by buying me a coffee! โ˜•

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *