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
byhttpsThis 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 [email protected]:haxkd/TestProject.git
Step 6: Confirm by running this line if you have successfully added it:
git remote -v
by sshThis will show various URLs related with your repositories including the one you just included.
Similar Reads
How to Use 'git remote add origin' Command? The `git remote add origin` command is used to add a remote repository to your local Git repository. This allows you to push and pull changes between your local and remote repositories. The term "origin" is an alias that refers to the remote repository URL. By convention, "origin" is used for the pr
2 min read
How to List Remote Branches in Git? Git is a powerful version control system that allows developers to collaborate on projects, maintain code history, and manage multiple lines of development through branching. One common task when working with Git is to list all branches in a remote repository. This article will guide you through the
3 min read
How to Add Submodule in Git? Git is a widely used distributed version control and source code management system. It effectively tracks changes to source code, enabling easy branching, merging, and versioning. In this article, we will explore the concept of Git submodules, their benefits, and best practices for integrating them
4 min read
How To Delete Remote Branch in Git? Git is an important tool in the process of application development and is used widely in the software industry by developers to maintain the codebase. Using this developers are able to organize their codebase and manage the version history of their project. Now, as a developer, you need to know how
1 min read
How to Add Upstream in Git? When you fork a repository, you create a copy of it under your own account. However, as the original repository updates with new features, bug fixes, and improvements, you'll want to keep your forked repository up-to-date with these changes. This is where adding an upstream remote in Git comes into
3 min read
How to Remove a Remote Branch in Git? Git is an essential tool for version control in modern software development. It allows multiple developers to collaborate on a project efficiently by managing changes to the source code. One common task when managing a Git repository is removing remote branches. This might be necessary when a featur
3 min read
Remote Add Origin vs Remote Set-Url Origin in Git Git is an important tool for version control, allowing multiple developers to track and manage changes to code bases efficiently. Among its various functionalities, the commands remote add origin and remote set-url origin play important roles in managing remote repositories. This article will explor
3 min read
How to Login to Git? Git is a popular version control system used by developers to manage code and collaborate on projects. To fully utilize Gitâs features, you need to log in, which involves setting up authentication with a Git hosting service like GitHub, GitLab, or Bitbucket. In this article, weâll guide you through
3 min read
How To Fetch Remote Branches in Git ? Git provides a powerful version control system that allows developers to collaborate efficiently on projects. Over time, however, a repository can have local and remote branches. Local branches are created locally and only exist on local machines and the remote branches exist on the remote repositor
3 min read
How to Checkout Remote Branch in Git? When working on collaborative Git projects, managing different versions of your code through branches is crucial. Often, developers need to switch between branches, especially remote ones, to work on specific features or bug fixes. In this comprehensive Git tutorial, weâll teach you how to easily ch
5 min read