Git Remote Command

Git Remote Command: In our previous posts, we discussed how to create a GitHub repository on the cloud. This means that you can upload the data from your Local Repository to a Remote Repository on GitHub. You will need to create an account on GitHub, and then you can push your local data to a remote location on GitHub.

So, in this post, we are going to cover the topics below in a detailed manner:

  • How to connect the Local Repository with the Remote Repository?
  • What is the Git Remote command?
  • How to get Remote Repository details?
Post Type:GIT Tutorial
Published On:www.softwaretestingo.com
Applicable For:Freshers & Experience
Get Updates:Join Our Telegram Group

Here are a few ways you can link your local repository to a remote one:

From remote: If you want to create a copy of a repository that is already on GitHub, you can use the Git Fork command. With this command, you can make a git fork or git clone of the same repository locally.

From local: This can be done by using the Git Remote command when the repository is first created locally. By connecting it to the remote repository, the user will be able to access it from anywhere.

In the meantime, we will follow the second approach (From local), where a user has a local repository and an empty remote repository that are not connected to each other.

Git Remote Command in Git

A git remote command is used to manage a connection between a local and remote repository. For example, you can use the git remote command to connect your Git local repository with GitHub’s remote repository.

After reading the above statement, if you think after running the git remote command, the live exchange of data will happen in local and remote repositories, then this is not the case. Git remote is just a connection between the local and GitHub repository.

Instead of having to remember the long, complicated URL for each GitHub repository you want to connect to, you can give that repository a nickname with git remote. That way, you only have to remember the name you gave it instead of the entire URL.

Git remote is a way of referencing GitHub repositories that don’t provide real-time access to your local changes. In other words, whatever you do locally won’t be reflected on your GitHub repository without your permission.

Now, let’s see how to link an existing local Git repository to a remote GitHub repository. If you go back to your GitHub repository, you can notice something like the following:

Git Remote Command 1

Connect Local Repository with GitHub Remote Repository

This section will try to link your local repository to the GitHub repository. To do this, follow the below steps:

The very first thing we have to do is go to the git repository that you want to link. and from that folder, you have to open the git bash.

Git Remote Command 2

Before making any changes, it’s a good idea to check if the repository is clean and if nothing is outstanding by using the git status command.

Git Remote Command 3

Then, execute the git remote command.

Git Remote Command 4

After executing the git remote command, there is no output because there is no linked repository as of now. So, if you look at the pic or you can check this on your Git repository, there itself it is mentioned how you can connect to your GitHub repository.

Git Remote Command 5

Or you can execute the below command:

git remote add origin https://github.com/softwaretestingo/Demorepo.git

Git Remote Command 6

Once you have executed the above command successfully, you are done with connecting the local repository, which will be linked to the GitHub repository. Because this time, we have mentioned which one is the remote repository and the remote repository URL.

How to check if the Local Repository is connected with the Remote Repository?

After connecting the local repository with the GitHub repository by executing the git remote add origin command in Git bash, you are not getting any success or failure message. So, If you want to check whether your repository is linked, run the git remote command.

Git Remote Command 7

If you’d like to view the origin repository, it’s available for you to use. You can use the git remote -v command to see the same result, which will also include the URL.

Git Remote Command 8

Categories GIT

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment