Git Remote Command: In our previous posts, we have discussed how we can 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 below topics 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|
|Applicable For:||Freshers & Experience|
|Get Updates:||Join Our Telegram Group|
How to Link an Existing Git Local Repository to Remote Repository?
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 on local. 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 then you can notice something like the below:
Connect Local Repository with GitHub Remote Repository
In this section, we will try to link your local repository to the GitHub repository. So to do this follow the below steps:
The very first thing we have to do is go to the git repository which you want to link. and from that folder, you have to open the git bash.
Before you make any changes, it’s a good idea to check if the repository is clean and if there is nothing outstanding by using the git status command.
Then execute the git remote command
After executing the git remote command there is no output because there is no linked repository as of now. So if you look below the pic or you can check this on your git repository, there itself it is mentioned about how you can connect to your GitHub repository.
Or you can execute the below command:
git remote add origin https://github.com/softwaretestingo/Demorepo.git
Once you have executed the above command successfully, then you are done with connecting the local repository will be linked to the GitHub repository. Because this time we have mentioned which one if 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.
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.
Leave a Reply