-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cff4277
commit 19c84bb
Showing
1 changed file
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
--- | ||
title: Reset master to match remote | ||
type: snippet | ||
title: Reset your local master branch to match remote | ||
shortTitle: Reset master to match remote | ||
type: tip | ||
language: git | ||
tags: [repository,branch] | ||
cover: old-consoles | ||
dateModified: 2021-04-13 | ||
excerpt: Learn how to quickly and easily reset your local `master` branch to match the one on the remote. | ||
dateModified: 2024-03-31 | ||
--- | ||
|
||
Resets the local `master` branch to match the one on the remote. | ||
If you've ever worked with Git, chances are you've encountered a situation where your local `master` branch is **out of sync with the remote**. This can happen if you've made some local changes to the `master` branch and want to reset it to match the one on the remote. | ||
|
||
- Use `git fetch origin` to retrieve the latest updates from the remote. | ||
- Use `git checkout master` to switch to the `master` branch. | ||
- Use `git reset --hard origin/master` to reset the local `master` branch to match the one on the remote. | ||
The first step to fix this is to make sure you have the **latest updates** from the remote. You can do this by using `git fetch origin`. After that, you can **switch** to the `master` branch using `git checkout master` and **reset** it to match the one on the remote using `git reset --hard origin/master`. | ||
|
||
```shell | ||
git fetch origin | ||
git checkout master | ||
git reset --hard origin/master | ||
# Syntax | ||
# git fetch origin | ||
# git checkout master | ||
# git reset --hard origin/master | ||
|
||
# Examples | ||
git fetch origin | ||
git checkout master | ||
git reset --hard origin/master | ||
# Local `master` branch is now up to date with remote `master` | ||
``` | ||
|
||
> [!TIP] | ||
> | ||
> You can follow this process for **any branch**, not just `master`. Simply replace `master` with the name of the branch you want to reset. |