Friday, May 1, 2015

GitHub : A Cheat Sheet

This post is for me in the future, or any one else who is just starting or wanting to clean up their GitHub game.

First Things First

    $ git status
    • If five seconds have passed by and you haven't typed git status, you're doing it wrong.
Errors
  • Remember git is your friend. When errors come up do not panic or make hasty changes. First slowly read through the comment git provided with the error. Often you will find your solution is provided.

Get Started

    $ git clone <repo_url>
    • To get the repository you want to work on create a local copy in your current directory

Per Feature You Implement - Create a new branch

    $ git checkout <latest_qa_or_production_branch>
    • Will switch you to the specified directory, this updates your local directory files to match those in this existing branch
    $ git pull origin <latest_qa_or_production_branch>
    • Will pull changes from the locally stored branch and merge them onto the locally checked out branch
    $ git checkout -b <new_feature_branch_name>
    • Will create a new branch locally and make that your working directory
    • -b saves you from having to write git branch < .. > before git checkout < .. >

Per Change You Make to the Feature

    $ git add <file_changed_or_directory_changed>
    • Updates the index to have all the changes made in the file or directory specified
    • If you enter $ git status at this point you will see a list of the "Changes to be committed"
    $ git commit -m <commit message>
    • Stores the current copy of the index and a log message from the user, basically it packages up the changes you've made and your message explains why they are needed
    $ git pull origin <latest_qa_or_production_branch>
    • This step is vital to check that your changes are compatible with the existing branch
      • Fun times. This could be the step that is the most exciting as you have to muddle through merge conflicts
    $ git push origin <new_feature_branch_name>
    • Hurray! You have now pushed your local changes to the remote repository
    Go to GitHub
    • Create a pull request setting the 'base' to the <latest_qa_or_production_branch> and 'compare to' <new_feature_branch_name>
    • Review the highlighted differences
    • Merge pull request
      • Note: As I am currently just working on my own projects I merge my own pull requests, but of course with a team you may not be merging your own requests.
To Tie It Up

    $ git checkout <latest_qa_or_production_branch>
    $ git pull origin <latest_qa_or_production_branch>

No comments:

Post a Comment