Add existing local repo to new online repo
To add an existing local repository to a new online repository, you'll need to follow these steps:
Step 1: Create a new online repository
- Go to the online repository platform (e.g., GitHub, GitLab, Bitbucket) and create a new repository.
- Give your repository a name, description, and choose the type of repository you want to create (e.g., public, private, empty).
Step 2: Initialize your local repository
- Open your local repository directory in your terminal or command prompt.
- Run the command
git init
to initialize your local repository if it's not already initialized.
Step 3: Add your local repository to the online repository
- Run the command
git remote add origin <online-repo-url>
to add the online repository as a remote repository. Replace<online-repo-url>
with the URL of your online repository.
For example, if your online repository is on GitHub, the command would be:
git remote add origin https://github.com/your-username/your-repo-name.git
If your online repository is on GitLab, the command would be:
git remote add origin https://gitlab.com/your-username/your-repo-name.git
If your online repository is on Bitbucket, the command would be:
git remote add origin https://bitbucket.org/your-username/your-repo-name.git
Step 4: Push your local repository to the online repository
- Run the command
git push -u origin master
to push your local repository to the online repository. This will create a new branch calledmaster
on the online repository.
If you want to push a different branch, replace master
with the name of the branch you want to push.
Step 5: Verify the connection
- Run the command
git remote -v
to verify that your local repository is connected to the online repository.
You should see the URL of your online repository listed as the origin
remote.
That's it! Your existing local repository should now be connected to your new online repository.