git Flow Class

Before we start

  • Does anyone have any particularly horrible git-tastrophes that they'd like to share?

  • Any burning questions?

  • Setting your OSX Keychain

Git Flow

this

Some more useful commands

  • git diff

    • shows all of the additions and deletions in your working directory
  • git remote -v

    • check all remotes associated with local repo
  • git remote add <name(ie. origin or upstream)> <url>

    • add another remote repo to your local repository
  • git stash

    • saves the state of your working directory.
    • It also reverts you back to a clean directory at your HEAD commit.
  • git stash pop

    • gives you back changes from your last stash
  • git stash apply

    • allows you to revert to a previous stash by either specicfying ie. git stash apply stash@{2}, which will take you back to the specified stash.
    • Or, simply typing git stash apply will revert to your most recent stash.
  • git reset --hard

    • This resets the index and the working tree. Any changes to tracked files since the last commit are discarded.
  • git reset

    • This does not touch the index or working tree but resets the head to the latest commit and leaves all files unstaged.
  • Setting your git config to use a certain text editor

    • git config --global core.editor "sublime —wait"

Git Workflow, according to GitHub

It's useful to think of branches like JavaScript functions: they should be small, have descriptive names and implement a single feature. Use branches for the small features that you can implement quickly.

Activity: Conflict Resolution

In pairs assign one person the role of Person 1 and the other Person 2.

  1. Person 1: Create a repo on Github with a README. Add Person 2 as a Collaborator.

  2. Extra Challenge(optional): Add 2 issues to your github issues, one for Person 1, the other for Person 2.

  3. Both: checkout a unique branch.

Example:

git checkout -b person1-update-readme

git checkout -b person2-update-readme

  1. Both: Make changes to the same line in the README in both repos.

  2. Person 1: Push your branch and open a PR.

  3. Person 2: Merge the PR

  • If doing the extra challenge: close the issue assigned to Person 1 via a commit message.
  • halp?
  1. Person 2: Push your branch and open a PR.
  • Notice that we can’t merge it automatically
  • We need to fix it locally first
  1. Person 2: checkout the master branch.

  2. Person 2: Pull from master on Github.

  3. Person 2: Checkout the branch you have an open PR for.

  4. Person 2: Merge master into your current branch.

  • This should throw an error CONFLICT (content): Merge conflict in readme.md Automatic merge failed; fix conflicts and then commit the result.
  1. Person 2: Open the file it says the conflict occurs in. You can see it if you run git status

  2. Person 2: You see something that looks like this:

<<<<<<< HEAD
Person 2 adds a line!
=======
Person 1 Adds a line!
>>>>>>> master
  1. Person 2: Update the line to look the way you want it to look
  • Remove the <<<< HEAD, =======, and >>>> master lines
  1. Person 2: running git status tells you how to mark the conflict as resolved
  • After resolving and running git status you will see a Changes to be committed message.
  1. Person 2: Commit the resolved changes

  2. Person 2: Push the changes to your branch on Github

  3. Reload the pull request

  • It should now be able to be merged in automatically
  • You should also see the commit that merged the two changes
  • If doing the extra challenge: Person 1: Merge the PR and close the issue via your commit message. halp?
  • If not: Person 1: Just merge the PR