Its often the case that we would have worked on different projects and never really uploaded our work to github. There are 2 different scenarios that I often found myself in.
- .git repo present locally that is not yet added to github
- code that is not yet added to github
Effectively I am going to talk about solving 1 only. I will point out a way in which scenario 2 can be reduced to scenario 1 and therefore the solution applies for both the cases.
Scenario 1: .git repo present locally
Firstly we need the repo to have a github remote. To list the remote destinations for a git repo,
$> git remote -v
[Remember to type this command from within the git repo directory - as git command looks up .git folder in the current directory for its operations]
Secondly, create and initialize an empty repo in github and get the Clone URL for the repo. Here I will talk only about HTTP clone URL, for simplicity. [Note that it is actually https:// URL]
Thirdly, do the following:
$> git remote add <remote name> HTTP clone URL
$> git push <remote name> master #for pushing master branch on to the remote
We are all set. We have uploaded our git repo onto github.
Scenario 2: code (without local git repo) that is not yet added to github
To create a git repo locally, we can do the following:
$> git init
$> git add required files
$> git commit -m"sample message"
Now, we have reduced scenario 2 to scenario 1 and we will be able to upload our code to github.
References:
http://stackoverflow.com/questions/10573957/how-to-push-from-my-local-repository-to-my-github-repository
http://caiustheory.com/adding-a-remote-to-existing-git-repo
http://caiustheory.com/adding-a-remote-to-existing-git-repo