How To Upload Your Project to Github

Warning
Using free Github account will cause your project to be visible publicly

Often you’re solving a very tricky programming problem and it’s hard to describe it on forum. One very useful thing to do is to isolate the problem by creating a small project and share it. This can be done easily using git and .

  1. Install git if your PC/Mac doesn’t come with one. Use git --version on a terminal shell / command prompt to check.
  2. if you haven’t got one
  3. To avoid having to type in password each time you upload / sync code to github, let’s setup public/private key authentication. This only need to be setup once per PC. First check if you already have a ssh keypair. On windows: open explorer > right click > git bash (or just open a terminal shell on OSX / Linux) > check if you have the file ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub. If you don’t, generate a new one using ssh-keygen (accept all the default setting)
  4. On github . Paste the content of ~/.ssh/id_rsa.pub.
  5. Create new github repository. Give it your project name (eg: foobar).
    github
  6. Back in your computer, point your git shell to the root of your project and run these commands:
    $ git --init
    # You may want to create a .gitignore file before proceeding to
    # next command, see below
    $ git add -A
    $ git commit -m 'initial commit'
    # Change mygitusername and foobar
    $ git remote add origin :mygitusername/foobar.git
    $ git push -u origin master
    

    It’s a good practice to add a .gitignore to avoid tracking binaries and project metadata. Do this before git add -A. This is my typical .gitignore file for a maven java project:

    # All files paths matching these prefix will not be tracked by git
    target
    .settings
    .project
    .classpath
    .springBeans
    
  7. Congratz, you project is now up in github. It’s also a good practice to add a README.md file to include instruction on how to run your project. Run following commands for subsequent changes you want to push to github:
    $ git add -A
    $ git commit -m 'fixed bugs abcd'
    $ git push
    

Leave a Reply