πŸŽ‰ Special Offer !    Code: GET300OFF    Flat β‚Ή300 OFF on every Java Course
Grab Deal πŸš€

Connecting & Managing Repositories - git remote


Introduction

  • git remote command is used to manage remote connections in a Git project.
  • A remote is a version of your project that is hosted on the internet or another network β€” commonly on platforms like GitHub, GitLab or Bitbucket.
  • What does git remote do ?
    • Lists all the remote repositories connected to your local Git project.
    • Allows you to add, remove, rename and inspect remote repositories.
    • Helps you collaborate with others by pushing to or pulling from remote repositories.

How to use git remote ?

  1. Open the Git terminal (or command prompt) and navigate to the project folder where your Git repository is initialized.
  2. Check Existing Remote Repositories:
    • git remote
      • It will show the names of all connected remotes (e.g., origin).
    • git remote -v
      • It will display the URLs of the remotes along with their fetch/push information.
  3. Add GitHub Repository (If Not Connected Yet):
    • If there is no existing remote, or you're adding it for the first time, run the following command:
      • git remote add origin https://github.com/SmartProgrammingCoders/GitDemo.git
    • This command links your local Git project to the GitHub repository.
    • Here :
      • origin : It is the nickname for your GitHub repo (can be anything).
      • https://github.com/SmartProgrammingCoders/GitDemo.git : It is the repository URL i.e. actual location of your GitHub repository which we have created in previous tutorial.
  4. The commands will show the following output:
    • Git Remote Add GitHub Repository Command

Other git remote commands:

  1. Show All Remotes:
    • Example:
      • git remote
    • This lists the names of all connected remotes (e.g., origin, upstream).
  2. Show Remote URLs:
    • Example:
      • git remote -v
    • This displays the fetch and push URLs of all remotes.
  3. Show Detailed Info About a Remote:
    • git remote show <name>
    • Example:
      • git remote show origin
    • Shows detailed information such as branches, fetch/push URLs, tracking info, and more.
  4. Add a new remote:
    • git remote add <name> <remote-url>
    • Example:
      • git remote add origin https://github.com/SmartProgrammingCoders/GitDemo.git
    • This sets up a connection named origin to your GitHub repo.
  5. Rename a remote:
    • git remote rename <old-name> <new-name>
    • Example:
      • git remote rename origin gitdemorepo
    • This renames the remote from origin to gitdemorepo.
  6. Remove a remote:
    • git remote remove <name>
    • Example:
      • git remote remove origin
    • This removes the remote connection named origin.
  7. Change the URL of an Existing Remote:
    • git remote set-url <name> <new-url>
    • Exmaple:
      • git remote set-url origin https://github.com/SmartProgrammingCoders/NewRepo.git
    • This updates the URL of the existing remote named origin.