118

I have a local repo. I created the whole app but now I want to push it to remote repo. I already have remote repo as well. How can I connect these two repos without losing any work that I did?

Om3ga
  • 24,135
  • 40
  • 122
  • 201

3 Answers3

173
git remote add origin <remote_repo_url>
git push --all origin

If you want to set all of your branches to automatically use this remote repo when you use git pull, add --set-upstream to the push:

git push --all --set-upstream origin
vergenzt
  • 8,013
  • 4
  • 29
  • 42
  • remote repo url should something like this? `https://example.com/projects/luotsi/repositories/git/marketing-site-redux` – Om3ga Jun 25 '12 at 11:54
  • 2
    Probably, yes. It usually ends with something like `https://example.com/.../reponame.git`, although the `.git` ending is not technically required. – vergenzt Jun 25 '12 at 11:56
  • The easiest way to find out is to try it and see. Git will let you know if it's not right. – vergenzt Jun 25 '12 at 11:57
  • I did it it give me this error `fatal: Not a git repository (or any of the parent directories): .git` – Om3ga Jun 25 '12 at 11:59
  • 2
    Is your app in a local repository yet (i.e. have you at some point done `git init` and made commits and stuff)? That error message means you're not in a repository. – vergenzt Jun 25 '12 at 12:01
  • 4
    go one folder level down, your repo is in another castle – Chris McCall May 17 '13 at 22:52
2

One line exact answer is provided by "vergenzt" but if you want to go through the detail on how to commit your code and connect local and remote github repo and push code into remote repo using git cli, you can go through this article : https://medium.com/geekstrends/a-beginners-guide-to-starting-with-git-cli-1d5c44af0a4

USMAN FAZIL
  • 444
  • 4
  • 7
1

I know it has been quite sometime that you asked this but, if someone else needs, I did what was saying here " How to upload a project to Github " and after the top answer of this question right here. And after was the top answer was saying here "git error: failed to push some refs to" I don't know what exactly made everything work. But now is working.

Community
  • 1
  • 1
バカです
  • 183
  • 2
  • 3
  • 15