Get new changes from the remote with fetch and pull

Description: A teammate pushed a new commit. First check the new commits without changing your branch, and then update your branch.

Hint:

  • git fetch downloads without merging. git pull downloads and merges.

Solution

Terminal output

$ git fetch
From /home/robin/server
0f2bd93..66c2a05 main -> origin/main
$ git log HEAD..origin/main –oneline
66c2a05 (origin/main, origin/HEAD) Mate adds a file
$ git pull
Updating 0f2bd93..66c2a05
Fast-forward
mate.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 mate.txt
$ ls
app.txt
mate.txt

How it works

  • After the fetch, the commit is known as origin/main, but our branch did not move.
  • git pull then merged it (a fast-forward), and the new file is in our folder.

Read Git Fetch and Pull.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.