Wednesday, June 19, 2013

Different ways of setting up a repo on github

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. 

  1. .git repo present locally that is not yet added to github 
  2. 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:


1 comment:

  1. That's really insightful. Few months back, i had a lot of problems with git hub and at last stack over flow saved my bun. Keep'em coming .

    ReplyDelete