Common Git Procedures

Grab a file from another branch

git checkout new-feature path/to/app.js

 

Merge feature branch into current

  • git merge feature/IRMEDUI-####   // Maybe or maybe not?

 

Pull something back from "add" to "unstaged"

  • git reset HEAD "Web/*.js"

 

Undo back a number of commits

  • git reset HEAD^

git reset HEAD^3   // add a number for multiple, base 1, rolls back everything including 3rd last commit

From < https://stackoverflow.com/questions/15772134/can-i-delete-a-git-commit-but-keep-the-changes>

  • Next time:, try also looking into…

git revert -n <sha>    // sha=commit hash??, read more at link above.

 

List all files in commits

Script: list-files-in-commit.sh

git show --name-only $1

 

List all commits in my current branch

Script: list-changes.sh

git log origin/master..HEAD --author=ej0202 --pretty="format:%cD %s (%h)"

 

Start a new feature branch

  • Get a user story ID from JIRA (IRMEDUI-####)
  • Setup a new branch for your feature (such as1637)
    • git checkout Forecast_CI
      • 10/25? (Bob says master, Justin/Thomas say Forecasting).
      • 11/27 Confirmed forecasting with both Justin and Thomas.
      • 11/30 Bob said "never do that".
      • 1/7 jjh assumptions under new ci branch.  Create branches off of master.  Merge in Forecast_CI.  Create pull requests off of Forecast_CI (p.k.a Forecasting).
      • 1/7 Justin - Base new branches from Forecast_CI not master from here on out.
    • git pull (make sure your local master is up to date with origin/master remotely)
    • git checkout -b "feature/IRMEDUI-####"
      • Above is functional equivalent of:

        git branch feature/IRMEDUI-####
        git checkout feature/IRMEDUI-####

    • Workflow question: Should I automatically "push" right at this point or wait until closer to completion when I'm ready to do a "pull request".  STATUS: wait until later
    • git push (just for the sample command line text like below)
    • git push --set-upstream origin feature/IRMEDUI-####

 

Start a new branch from current branch and switch to it

  • git checkout -b "feature/IRMEDUI-####"
    • Above is functional equivalent of:
      (all commands work from current branch in current workarea)

      git branch feature/IRMEDUI-####
      git checkout feature/IRMEDUI-####

 

Update a local branch from remote github

  • git checkout Forecast_CI  (switch to that branch in local workarea)
  • git pull (grab latest remote files and pull them into your local "Forecast_CI"