'Connect a local repository with a remote repository
I have a local repository. I created the whole application, but now I want to push it to a remote repository. I already have remote repo as well. How can I connect these two repositories without losing any work that I did?
Solution 1:[1]
A one line exact answer is provided by vergenzt, but if you want to go through the details on how to commit your code and connect a local and remote GitHub repository and push code into the remote repository using Git CLI, you can go through this article: Beginners guide to Git using CLI
Solution 2:[2]
First make this command:
git remote add origin {URL for the remote repository}
Then tab this command:
git push origin master
Note the name of master is the name of the remote repository on GitHub. If it has another name, like main or something else, make it instead of master.
It's expected to connect and push your local repo now. If something happens or any error appear, try this command:
git pull --rebase origin master
Solution 3:[3]
If you have
- your local project already tracked by git,
- an empty remote repository existing, which you want to contain the project,
do the following steps:
cd existingLocalRepo
git remote set-url origin <remote_repo_URL>
git push -u origin --all
Explanation:
- navigate to your local repo
- tell git where the remote repo is located
- upload/push your local branches to the remote repo
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Mortensen |
Solution 2 | Peter Mortensen |
Solution 3 | Sparkofska |