Github 101 for hackathons

This blog post is a HOWTO guide for using github while collaborating during hackathons. It does not cover git in detail.

One time setup

  1. Create github account by visiting https://github.com
  2. Generate SSH key locally and upload it to github

This setup ensures password-less (code) pull and push from github.

Per project setup

  1. Create a repo on github by submitting form at https://github.com/new
  2. Clone the repo locally using
    git clone git@github.com:@.git

    This URL is mentioned on the bottom right side of the repo page.
    Note: It’s recommended to use the above style (SSH) instead of the HTTPS style so that, future submissions do not require retyping password.

  3. This will clone the (empty) repo into <reponame> directory.
  4. After “cd”ing that directory, you will be working on the master branch.
  5. Change to a new branch say user1 using
    git checkout -b user1

    Note: “-b” creates a branch and checks it out. If branch already exists, the command will fail, remove “-b” to check out (work on) that branch.

  6. To see which branch you are currently and how much its modified use,
    git status
  7. Now modify the files.
  8. To add a new file, after creating the file, do
    git add filename
  9. To remove a file, do
    git rm filename
  10. All the changes made till this point are uncommitted, to see what changes will be committed in next commit, use
    git status

    and

    git diff
  11. Once the changes look good, commit them using
    git commit -m ""
  12. Now, the changes have been committed locally to user1 branch, to push the changes back to remote server (github), use
    git push origin user1
  13. Now the changes have been pushed to user1 branch on github server. Merge them by creating a pull request using master as base and user1 as branch to be merged.
  14. Step 13 can fail master has changed since the last time user1 was updated with master (in step 5). A fix for that is to execute following command before doing git push (step 12).
    git pull origin master
    

    In case of merge conflicts, this pull will produce files which had merge conflicts, review them looking for conflict markers (“<<<<“, “>>>>”) and merge the code manually.
    After than perform another commit using git commit and continue from step 12.

Some more productivity tools focused on git

  1. My .gitconfig file for colors, aliases and some other settings.
  2. git auto completion on command line.
  3. vim-fugitive for vim users.

Leave a Reply

Your email address will not be published. Required fields are marked *