Creating a Remote Repository and Connecting with git remote add
Creating a Remote Repository and Connecting with git remote add
Connecting your local repository to a remote repository on GitHub bridges your local computer with the global cloud. The git remote command manages these connections.
1. Creating a Remote Repository on GitHub
- 1Log into your GitHub account.
- 2In the upper-right corner, click the
+icon and select New repository. - 3Fill in the repository details:
- Repository name: e.g.,
ecommerce-dashboard. - Description: Short explanation of the project.
- Visibility: Choose Public (visible to the world) or Private (restricted to you and invited collaborators).
- Initialize this repository with:
- > [!IMPORTANT]
- If you are pushing an existing local repository, uncheck "Add a README file",
.gitignore, and license! Creating these on GitHub will create an initial commit on GitHub, causing diverged history that blocks your first push.
- 1Click Create repository.
2. Understanding Git Remotes: The origin Convention
A remote in Git is simply an alias (a bookmark shortcut) pointing to the URL of a repository hosted on the internet or a local network.
By universal convention in the Git ecosystem, the primary default remote repository is named origin.
3. Connecting Local Repo to Remote (git remote add)
GitHub displays quick-setup terminal instructions. To link your existing local repository to the remote URL:
Using SSH URL (Recommended):
Using HTTPS URL:
4. Managing and Inspecting Remotes
A. List Configured Remotes
B. List Remotes with Fetch and Push URLs (-v verbose)
Output:
C. Change a Remote URL (set-url)
If you switch from HTTPS to SSH or if the repository was renamed:
D. Remove an Outdated Remote (remove)
Practice Quiz
origin?Pushing and Pulling Code: git push -u origin main and git pull
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.