Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Git & GitHub IntroductionChapter 6. Remote Collaboration

Download Remote Repository and Merge to Local Repository – Git Pull

Download Remote Repository and Merge to Local Repository – Git Pull

Merging Remote Changes Locally with git pull

Pull is used when you want to download the latest Remote Repository information and merge it with the existing branch in the Local Repository. git pull is the command used to execute the pull action. The git pull command is often explained as a shortcut command for git fetch and git merge. As the git pull command shortcuts the manual checking process of the Remote Repository information, it may create a conflict. For a simple operation, you can use the pull command. However, generally, it is safer to use the git fetch command and check the Remote Repository status first before executing the git merge command.

For a better understanding, please go through the following practice section.

Practice

Objective:
Check how the pull operation works from both the repository owner and collaborator's points of view

In this practice, we'll use the following two users: Developer A and Developer B.

1. Download the project files for the first time: $ git clone

This is the same step we explained in Chapter 3. As we are using a different repository, you need to go through the same process again.

bloovee-round-icon.pngAction by Developer A

Before Developer B accesses the Remote Repository, Developer A needs to grant access to it.

Go to Settings of the repository and select Manage access. Press the green button to add a collaborator.

Add a collaborator to a GitHub repository: Step 1

Find a collaborator. In this demo, we invite sky-blue2022 (Developer B).

Add a collaborator to a GitHub repository: Step 2

Next, we'll be explaining the steps from Developer B's point of view.

skyblue-round-icon.pngAction by Developer B

After Developer A sends an invitation, Developer B receives an email with the invitation like shown below.

Accept the collaboration invitation on GitHub: Step 1

Click View invitation and press the Access invitation button like in the image below.

Accept the collaboration invitation on GitHub: Step 2

Now you as Developer B have access to the Remote Repository. To clone the project file, click the Code button and copy the URL for HTTPS.

Copy a URL for the Git Clone command

Go to the command line and run the git clone command.

Open the main project directory

When you run the git clone command., make sure that the current directory is where you want to create the project directory. In this project, you need to set the project's main directory for Developer B (e.g., Dev_B_skyblue) as the current working directory.

A quick way to open the directory with VS Code is by using drag & drop.

Open a project directory in VS Code using drag & drop

Open a new terminal. You can see that the project's main directory is shown in the EXPLORER section on the left and the directory is shown as the current working directory in the terminal.

Project directory and terminal UI in VS Code window

You can also use the command line to move the current directory to the main project directory.

Command Line - INPUT
cd ~/Dev_B_skyblue

Once you set the current working directory properly, run the command below.

Command Line - INPUT (for SSH)
git clone git@github.com:bloovee/git_remote_practice.git

or

Command Line - INPUT (for HTTPS
git clone https://github.com/bloovee/git_remote_practice.git

If the command successfully goes through as shown below, you'll see that the git_remote_practice directory is generated under the directory in which you executed the clone command.

Command Line - RESPONSE
Cloning into 'git_remote_practice'...
:
Resolving deltas: 100% (2/2), done.

2. Run the git pull command

At this stage, the HEAD of the master branch in each repository is the following.

  • Developer A's Local Repository: M1LA
  • Remote Repository: M2RA
  • Developer B's Local Repository: M2RA
Git Local repository and GitHub remote repository status illustration: Original status

From Developer B's point of view, at this stage, the statuses of the Remote Repository and the Local Repository on the master branch are the same; the HEAD is commit M2RA. This means that there is nothing you can pull on the master branch. However, Developer A's master branch lags behind.

To practice the pull command, we'll do the following actions:

  1. Pull the master branch on Developer A's local computer
  2. Further edit the master branch on Developer A's computer and push it to the Remote Repository
  3. Pull the updated master branch on Developer B's local computer

bloovee-round-icon.pngAction by Developer A

Run the pull command specifying the Remote Repository name (origin) and the master branch.

Command Line - INPUT
git pull origin master

You can see that the master branch was updated by the Fast-forward merge.

Command Line - RESPONSE
bloovee@MBP git_remote_practice % git pull origin master
remote: Enumerating objects: 5, done.
:
Fast-forward
 git_remote_practice.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

To confirm the commit status, check the log.

Command Line - INPUT
git log --oneline

You can see that the HEAD of the master branch in Developer A's Local Repository is the same as the Remote Repository's.

Command Line - RESPONSE
4e1a7d9 (HEAD -> master, origin/master) M2RA
4b30a1c M1LA

Next, edit the html file on the master branch.

git_remote_practice.html (master)
<!-- Master Branch-->
<h1>M1LA</h1>
<h1>M2RA</h1>
<h1>M3LA</h1>
<!-- /Master Branch-->

Commit the change with the commit message of "M3LA" and check the log to see the latest status.

M3LA indicates the following :

  • M – Master Branch
  • 3 – 3rd commit on the branch
  • L – Committed in the Local Repository
  • A – Committed by Developer A
Command Line - INPUT
git commit -am "M3LA"
git log --oneline

You can see that a new commit was successfully created as shown below.

Command Line - RESPONSE
4e7dbf9 (HEAD -> master) M3LA
4e1a7d9 (origin/master) M2RA
4b30a1c M1LA

Finally, push the master branch to the Remote Repository.

Command Line - INPUT
git push origin master

You can see that the latest commit was successfully pushed like shown below.

Command Line - RESPONSE
Enumerating objects: 5, done.
   :
To https://github.com/bloovee/git_remote_practice.git
   4e1a7d9..4e7dbf9  master -> master

Next, we'll be explaining the steps from Developer B's point of view.

skyblue-round-icon.pngAction by Developer B

Before running the pull command, let's check the commit status.

Command Line - INPUT
cd git_remote_practice
git log --oneline

You can see only two commits at this stage.

Command Line - RESPONSE
4e1a7d9 (HEAD -> master, origin/master, origin/HEAD) M2RA
4b30a1c M1LA

To bring the latest commit made by Developer A to Developer B's Local Repository, run the pull command.

Command Line - INPUT
git pull origin master

You can see that Fast-forward merge was executed.

Command Line - RESPONSE
remote: Enumerating objects: 5, done.
   :
From github.com:bloovee/git_remote_practice
 * branch            master     -> FETCH_HEAD
   4e1a7d9..4e7dbf9  master     -> origin/master
Updating 4e1a7d9..4e7dbf9
Fast-forward
 git_remote_practice.html | 1 +
 1 file changed, 1 insertion(+)

Check the commit status again.

Command Line - INPUT
git log --oneline

You can see that commit M3LA made by Developer A was merged with Developer B's master branch.

Command Line - RESPONSE
4e7dbf9 (HEAD -> master, origin/master, origin/HEAD) M3LA
4e1a7d9 M2RA
4b30a1c M1LA

3. Recap of this practice page

To review the summary of what we have done, you can check the illustration below.

Git Local repository and GitHub remote repository status illustration: After the push and pull command execution

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Essential Linux Key Commands

Chapter 2. Linux Key Commands

How to Commit Files with git commit

Commit Files – git commit

Verifying User ID and Group Information with id Command

id and groups (Check User ID and Group)

Git and GitHub Glossary of Terms

Git & GitHub Glossary

Managing Group Membership with gpasswd Command

gpasswd (Add and Delete Users to Group)

Essential Linux Key Commands

Chapter 2. Linux Key Commands

How to Commit Files with git commit

Commit Files – git commit

Verifying User ID and Group Information with id Command

id and groups (Check User ID and Group)

Git and GitHub Glossary of Terms

Git & GitHub Glossary

Managing Group Membership with gpasswd Command

gpasswd (Add and Delete Users to Group)

Tags:

Remote Repository

Pull

Remote Collaboration

Git Key Commands

Git & GitHub Introduction
Course Content

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features