The git remote add origin
command is used to add a remote repository to your local Git repository. The origin
is a shorthand name for the remote repository URL. Once you add a remote, you can push your local changes to the remote repository or pull changes from it.
Here’s the basic syntax:
git remote add origin <remote-repository-URL>
Example:
If you have a remote repository hosted on GitHub, you would do something like this:
git remote add origin https://github.com/username/repository-name.git
Steps:
-
Navigate to your local Git repository.
-
Run the
git remote add origin
command with the URL of your remote repository. -
Verify the remote was added by running:
git remote -v
This will list all the remotes associated with your repository.
Pushing to the Remote:
After adding the remote, you can push your local branch to the remote repository:
git push -u origin main
-u
sets the upstream tracking reference, so future git push
and git pull
commands will default to the origin
remote and main
branch.