Pull and Fetch Changes
Learn to pull and fetch changes from the remote repository and the difference between these two.
We'll cover the following
Once the remote code is changed, we may want to update the local content with the latest changes. We can do that by fetching and merging the code. It’s important to know the difference between git pull
and git merge
.
The git pull
command
In this course, git fetch
and git merge
are used more often than the git pull
command. The git pull
command is used only when we know that the user is the only person working on that branch.
The reason is that git pull
automatically merges the remotely changed code into our local branch. That works most of the time. But in rare cases, when we merge a remote code, it causes issues on our current codebase.
So, it’s better to fetch the remote code first. In the console, notice which files have changed on the external side. We can examine the changes before combining the code into our working environment. If we find issues with the remote changes, we can reject them and request that the teammate improve the code. We can fetch and merge later after the improvements are made.
Workflow to fetch remote code
Here’s a typical workflow when fetching remote code:
- Run
git fetch --all
to fetch to see any new updates from our teammates. - Run
git log --oneline --graph --all
to have a glimpse of the latest big picture. Read the one-line commit messages and inspect the commit paths. - If the teammates have updated code in our working branch, merge that branch with priority.
- Run
git diff current_branch origin/remote_branch
to inspect the changes. - Determine if merging the remote branch is appropriate.
- Merge the remote branch by running
git merge origin/remote_branch
.
Get hands-on with 1400+ tech skills courses.