Home > Linux, Software management > Importing Source Code to Github

Importing Source Code to Github

Github is a hosting service for software development projects using the Git revision control system. GitHub offers free accounts for open source projects (public repositories) and commercial plans for private repositories.

I’ve been using github for a while to clone source code, but I had never imported existing source code to github.

Here are the steps to follow:

  1. If you don’t have an account yet, sign-up for github.
  2. Setup github for Linux, Windows or Mac OS X.
  3. Create a repository as shown as explained here. You should now have a URL in github, something like [email protected]:user/repo_name.git, which we’ll use below.
  4. Go to the directory with your existing source code and create a local repo:
    git init 
    git add . 
    git commit -m "Initial commit"
  5. Finally, type the commands below to add your code to your new repository:
    git remote add somename [email protected]:user/repo_name.git
    git pull [email protected]:user/repo_name.git
    git push somename master

That’s it, anybody should now be able to clone you code as follows:

git clone git://github.com/user/repo_name.git

NB: If your existing source code (or part of it) comes from a git repository, you need to delete existing .git* files and directory first:

rm -rf `find . -name ".git*"`

or you won’t be able able to import your existing project to github and it will just upload an empty directory without source code.

Sources:

  1. http://stackoverflow.com/questions/2866872/how-to-upload-fresh-code-at-github
  2. http://stackoverflow.com/questions/4658606/import-existing-source-code-to-github
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

  1. Arcko
    May 7th, 2012 at 18:52 | #1
  2. May 7th, 2012 at 18:54 | #2

    @ Arcko
    Yes, but I could not find the instructions above in that page. It just shows how to do steps 1, 2 and 3.

    Edit: OK, Step 3 also shows how to add a README, but I did not read that part because README was automatically generated when I created the repo :p. Obviously I should have read it…

  3. Albert ARIBAUD
    May 8th, 2012 at 00:28 | #3

    The ‘git pull’ in step 5 is not necessary.

  4. May 8th, 2012 at 09:34 | #4

    @ Albert ARIBAUD
    I think I had to do that step because I clicked on “Initialize this repository with a README” when I created the repository.
    So If I run git push command directly, I get the following error:

    ! [rejected] master -> master (non-fast-forward)
    error: failed to push some refs to ‘[email protected]:cnxsoft/deleteme.git’
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes (e.g. ‘git pull’) before pushing again. See the
    ‘Note about fast-forwards’ section of ‘git push –help’ for details.

    But if the repo is completely empty, then you’re right and the ‘git pull’ request is not necessary.

  1. No trackbacks yet.