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

Link With Remote Repository – Git Remote

Link With Remote Repository – Git Remote

Establishing a Link with git remote

git remote is the command used when you want to establish and check the linking status between a Remote Repository and your Local Repository. There are some derivative commands and options for this command. We'll explain five major usages on this page.

Key Git Remote Commands
  • git remote add: Establish a link with a Remote Repository
  • git remote -v: Check the status of the linked Remote Repository
  • git remote rm: Delete the Remote Repository link
  • git remote set-url: Change the Remote Repository URL
  • git remote rename: Change the Remote Repository name

1. git remote add

Establishes a link between a Local Repository and a Remote Repository. As explained before, when you launch a project as the owner of the Remote Repository, you need to upload your project directory to the Remote Repository first. Before pushing the code, you need to establish a link between your Local Repository and the Remote Repository. The command to establish the link is git remote add. You need to specify a Remote Repository name and Remote Repository URL as shown below. The Remote Repository name is typically origin. You can get the URL from the Remote Repository page on GitHub.

git remote add [Remote Repository name] [Remote Repository URL]

2. git remote -v

Checks registered Remote Repositories. After you create a link with a Remote Repository by running the git remote add command or the git clone command, you may want to check the status of the link. git remote -v is the command used to check the status of the Remote Repository linked with your Local Repository. This command doesn't require any argument as shown below.

git remote -v

3. git remote rm

Deletes the Remote Repository link. When you want to deregister the link in the Remote Repository, the git remote rm command is used. To run the command, you need to specify the Remote Repository name as shown below.

git remote rm [Remote Repository name]

4. git remote set-url

Changes the Remote Repository URL. When you want to change an SSH connection to an HTTPS connection or you simply want to change the URL of the Remote Repository, you can run the git remote set-url command. When you run the command, you need to specify the existing Remote Repository name and new URL.

git remote set-url [existing Remote Repository name] [new URL]

5. git remote rename

Changes the Remote Repository name. The typical name of a Remote Repository is origin. However, there may be a situation, such as managing multiple Remote Repositories at the same time, when you want to use different names for the Remote Repositories. You can change the Remote Repository name by running the git remote rename command.

git remote rename [existing Remote Repository name] [new Remote Repository name]

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

Practice

bloovee-round-icon.pngDeveloper A (Project Owner Role)

Objective:
Check how the git remote commands work

1. Setup a practice project directory and file for this chapter

Directory and file structure

For this practice, we'll use the following directory and file. The directory and file will be used throughout the practices in this chapter.

  • Practice project directory: git_remote_practice
  • Practice file: git_remote_practice.html

The screenshot below is the target directory structure example based on Mac OS.

Git remote practice project directory example

Create the practice project directory and file

Open the project's main directory (e.g., Dev_A_bloovee) with VS Code. You can use drag & drop to open the directory.

Open a project directory in VS Code using drag & drop

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

Command Line - INPUT
cd ~/Dev_A_bloovee

After opening the project's main directory with VS Code, open a new terminal in the VS Code window and run the command below to create the directory and file.

Command Line - INPUT
mkdir git_remote_practice
cd git_remote_practice
touch git_remote_practice.html

Edit the practice HTML file

For the HTML file, make edits like those shown below. We'll use four branches. For practice purposes, create a coding section for each branch. For the first commit on the master branch, add <h1>M1LA</h1> after <!-- Master Branch-->.

M1LA indicates the following for practice purposes:

  • M – Master Branch
  • 1 – 1st commit on the branch
  • L – Committed in the Local Repository
  • A – Committed by Developer A
git_remote_practice.html (master)
<!doctype html>
<html lang="en">
<body>
<!-- Master Branch-->
<h1>M1LA</h1>
<!-- /Master Branch-->

<!-- Branch A-->
N/A
<!-- /Branch A-->

<!-- Branch B-->
N/A
<!-- /Branch B-->

<!-- Branch C-->
N/A
<!-- /Branch C-->
</body>

Create a Local Repository and make the first commit

As we are working on a new directory, we need to create a new Local Repository. Also, let's make the first commit with the commit message "M1LA", and check the commit status.

Command Line - INPUT
git init
git add .
git commit -am "M1LA"
git log --oneline

You can see that the first commit was successfully made.

Command Line - RESPONSE
hint: Using 'master' as the name for the initial branch. This default branch name
:
hint:   git branch -m <name>
Initialized empty Git repository in /Users/bloovee/Dev_A_bloovee/git_remote_practice/.git/
[master (root-commit) 4b30a1c] M1LA
 1 file changed, 19 insertions(+)
 create mode 100644 git_remote_practice.html
4b30a1c (HEAD -> master) M1LA

2. Create a Remote Repository

Next, create a new Remote Repository for this practice. Go to the GitHub website and log into your account. Click the + button on the top right and select New repository. You'll reach the page as shown below. Add the Repository name (use the same name as your project directory (git_remote_practice) to avoid confusion.

Creating a new GitHub repository

After you press the green button to create a new repository, you'll see the following Quick setup page.

First, we'll try to use the HTTPS connection. Copy the URL by clicking the button on the right.

GitHub remote repository URL: SSH

Go back to the command line and run the git remote add command with a Remote Repository name (typically, origin is used) and the URL copied from the GitHub website. Also, run the git remote -v command to check the Remote Repository status.

Command Line - INPUT (for HTTPS)
git remote add origin https://github.com/bloovee/git_remote_practice.git
git remote -v

You can see that the Remote Repository was successfully registered in your Local Repository.

Command Line - RESPONSE
origin  https://github.com/bloovee/git_remote_practice.git (fetch)
origin  https://github.com/bloovee/git_remote_practice.git (push)

3. Delete a Remote Repository link

To delete the Remote Repository link, run the git remote rm command as shown below. Also, run the git remote -v command to check the status.

Command Line - INPUT
git remote rm origin
git remote -v

There will be no response as the Remote Repository was already deleted.

For the next step, add the Remote Repository again.

Command Line - INPUT
git remote add origin https://github.com/bloovee/git_remote_practice.git
git remote -v

Confirm that the Remote Repository was correctly registered.

Command Line - RESPONSE
origin  https://github.com/bloovee/git_remote_practice.git (fetch)
origin  https://github.com/bloovee/git_remote_practice.git (push)

4. Change the Remote Repository URL

In this practice, we try to change the Remote Repository URL from HTTPS to SSH. First, get the new URL from the Remote Repository. Click the SSH button and click the right button to copy the URL.

GitHub remote repository URL: HTTPS

Run the git remote set-url command with the copied URL. Also, run the git remote -v command to confirm the status.

Command Line - INPUT (for SSH)
git remote set-url origin git@github.com:bloovee/git_remote_practice.git
git remote -v

You can see that the URL changed to SSH URL.

Command Line - RESPONSE
origin  git@github.com:bloovee/git_remote_practice.git (fetch)
origin  git@github.com:bloovee/git_remote_practice.git (push)

5. Change the Remote Repository name

Lastly, try to change the Remote Repository name. This time change the name from origin to origin_2 as shown below.

Command Line - INPUT
git remote rename origin origin_2
git remote -v

You can see that the name has changed to origin_2.

Command Line - RESPONSE
origin_2  git@github.com:bloovee/git_remote_practice.git (fetch)
origin_2  git@github.com:bloovee/git_remote_practice.git (push)

For the next practice, revert the name to origin.

Command Line - INPUT
git remote rename origin_2 origin
git remote -v

Confirm the name was changed back to origin.

Command Line - RESPONSE
origin  git@github.com:bloovee/git_remote_practice.git (fetch)
origin  git@github.com:bloovee/git_remote_practice.git (push)

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Understanding pwd Command in Linux

pwd (Print Working Directory)

Field Options in Django Models

Django Models – Field Options

Creating Django Templates for CRUD Operations

Django Templates for CRUD Views

Creating a Superuser for Django Admin Access

Create Superuser and Log In to Django Admin

Retrieving Command Information with type

type, which and whereis (Display Command Information)

Understanding pwd Command in Linux

pwd (Print Working Directory)

Field Options in Django Models

Django Models – Field Options

Creating Django Templates for CRUD Operations

Django Templates for CRUD Views

Creating a Superuser for Django Admin Access

Create Superuser and Log In to Django Admin

Retrieving Command Information with type

type, which and whereis (Display Command Information)

Tags:

Remote Repository

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