Skip to the content.

How To Update Your Local Repo With The Latest Changes

Usecase : When your local repo is behind the remote repo , and you want to update it with the latest commits before continuing your work. Example :

Now if you try to continue work locally without updating, you risk:

Two Ways To Update It

🔹1. Git Fetch + Merge

git fetch origin

Downloads new data (commits, branches, tags) from the remote repo (origin) into your local .git database, but does not change your working directory or current branch.

After running git fetch, you can compare differences:

git log master..origin/master

It shows commits in remote main that you don’t have locally.

log Output

git merge origin/master

It merges the commits from remote’s master branch (origin/master) into your current local branch.

merge output


🔹2. Git Pull

git pull origin master

It is actually a shortcut for two commands (fetch + merge). It fetches updates and then merges them automatically into your current branch.

Note:

Difficulty: ⭐ Beginner