Git Pull from GitHub

Git Pull from GitHub

Pulling to Keep up-to-date with Changes

While working on a project, one should get the most recent changes to the local copy.

With Git, that can be done with pull.

pull is a combination of two different commands:

  • fetch
  • merge

Git Fetch

fetch gets all the change history of a tracked branch/repo.

Fetch updates on the local Git to see what has changed on GitHub:

Example:

[user@localhost] $ git fetch origin

remote: Enumerating objects: 5, done.

remote: Counting objects: 100% (5/5), done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0

Unpacking objects: 100% (3/3), 733 bytes | 3.00 KiB/s, done.

From https://github.com/webhostguru/dynamic-drop-down

e0b6038..d29d69f  master     -> origin/master

Once we have the recent changes, we can check the status:

Example:

[user@localhost] $ git log origin/master

commit d29d69ffe2ee9e6df6fa0d313bb0592b50f3b853    (origin/master)

Author: webhostguru <77673807+webhostguru-test@users.noreply.github.com>

Date:   Fri Mar 26 14:59:14 2021 +0100

Updated README.md with a line about GitHub

commit e0b6038b1345e50aca8885d8fd322fc0e5765c3b (HEAD -> master)

Merge: dfa79db 1f1584e

Author: webhostguru

Date:   Fri Mar 26 12:42:56 2021 +0100

That seems okay as expected, but it can also be verified by showing the differences between the local master and origin/master:

Example:

[user@localhost] $ git diff origin/master

diff –git a/README.md b/README.md

index 23a0122..a980c39 100644

— a/README.md

+++ b/README.md

@@ -2,6 +2,4 @@

After this, the process of safely merging can take place.

Git Merge

The Git Merge combines the current branch, with a specified branch.

As, we know that the updates are as expected, and the process to merge the  recurrent branch (master) with origin/master:

Example:

[user@localhost] $ git merge origin/master

Updating e0b6038..d29d69f

Fast-forward

README.md | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)

Check our status again to confirm we are up to date:

Example:

[user@localhost] $ git status

On branch master

Your branch is up to date with ‘origin/master’.

nothing to commit, working tree clean

Git Pull

The pull is a combination of fetch and merge. The Git Pull command pulls all changes from a remote repository into the branch you are working on.

Make another change to the Readme.md file on GitHub.

Github pull

Use the pull command to update our local Git:

[user@localhost] $ git pull origin

remote: Enumerating objects: 5, done.

remote: Counting objects: 100% (5/5), done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0

Unpacking objects: 100% (3/3), 794 bytes | 1024 bytes/s, done.

From https://github.com/webhostguru/dynamic-drop-down

a7cdd4b..ab6b4ed  master  -> origin/master

Updating a7cdd4b..ab6b4ed

Fast-forward

 README.md | 2 ++

 1 file changed, 2 insertions(+)