Skip to main content
In this guide, you will learn how to work with remote repositories using Git. A remote repository is a version of your project hosted on services like GitHub, GitLab, or Bitbucket. When you create a repository on any of these platforms, you’re provided with a connection string (URL) that points to the remote location of your project.
The alias “origin” is commonly used to refer to the primary remote repository. This alias simplifies commands when pushing or fetching code without needing to remember the full URL.

Adding a Remote Repository to Your Local Project

Once you have created your remote repository, add it to your local project by executing the following command:
$ git remote add origin https://.../[name].git
This command links your project to the remote repository using the provided URL.

Sample Connection Strings

Below are some examples of connection strings from popular platforms:
https://github.com/kodekloudhub/stories.git
https://gitlab.com/kodekloudhub/stories.git
https://bitbucket.org/kodekloudhub/stories.git

Verifying the Remote Connection

After you link your local repository to the remote one, verify the connection details with:
$ git remote -v
origin  https://.../[name].git (fetch)
origin  https://.../[name].git (push)
This verification ensures that both fetching and pushing operations will use the correct remote repository, as identified by the alias “origin.”
Always check your remote configuration using the git remote -v command to ensure your project is correctly linked to the remote repository. This step is particularly important when collaborating with a team.

Summary of Essential Steps

  1. Create the remote repository on your chosen hosting platform.
  2. Use the provided connection string to link the remote repository to your local project.
  3. Verify the connection with the git remote -v command.
By following these steps, you are set to push your local code to the remote repository and collaborate seamlessly with your team. For more detailed information on Git and remote repositories, consider visiting the Git Documentation.