How to add remote origin in git?
Last Updated :
02 May, 2024
Git, most popular version control system, revolutionized the way developers collaborate and manage code. One important feature of Git is remote repositories, which serve as centralized hubs for code collaboration. In this article, we’ll explore the process of adding a remote origin to your Git repository.
What are Remote Origin?
In Git, a remote origin refers to the remote repository where your local repository’s code will be hosted. This remote repository could be on platforms like GitHub, GitLab, Bitbucket, or a private server. Adding a remote origin establishes a connection between your local repository and the remote repository, provides the exchange of code changes.
Adding a remote origin-
Using HTTPS
Step 1: Go to a remote repository on a platform such as GitHub, GitLab, or Bitbucket.
Step 2: Copy the HTTPS URL you can find at the top of the page.
Step 3: Open your terminal or command line.
Step 4: Navigate to your local repository folder.
Step 5: Use below command to add the remote origin:
git remote add origin <HTTPS_URL>
Here, <HTTPS_URL> will be the earlier mentioned your repo URL you copied from that site.
Like,
git remote add origin https://github.com/haxkd/CarService.git
Step 6: Check whether it has been added by running this code:
git remote -v
byhttps
This command will show the remote URLs associated with your repository.
Using SSH
Step 1: Proceed to your remote repository in the hosting platform like GitHub, GitLab, or Bitbucket.
Step 2: Copy down the provided SSH URL for cloning the repository.
Step 3: Open up a terminal or command prompt.
Step 4: Go to your local repository’s directory.
Step 5: Use this command to add a remote origin:
git remote add origin <SSH_URL>
Remember that <SSH_URL> should be replaced with the SSH URL copied before.
Example,
git remote add origin git@github.com:haxkd/TestProject.git
Step 6: Confirm by running this line if you have successfully added it:
git remote -v
by ssh
This will show various URLs related with your repositories including the one you just included.
Share your thoughts in the comments
Please Login to comment...