Skip to content

Instantly share code, notes, and snippets.

@ToniRib
Last active January 27, 2020 20:09
Show Gist options
  • Save ToniRib/d5955ba9c110b5eaf40d3ec43a168533 to your computer and use it in GitHub Desktop.
Save ToniRib/d5955ba9c110b5eaf40d3ec43a168533 to your computer and use it in GitHub Desktop.

Some handy git aliases for the command line. The $argv syntax is from fish, but for bash functions you can use $1.

stashlist

Lists the most recent 5 stashes. Shows commit sha/message, who created the stash, and file stats.

git stash list --stat -5 --pretty=format:'%C(yellow)%gd: %C(green)%s %C(blue)[%cn]'

Usage & Output

stash@{0}: WIP on 169348064-show-freshbooks-connected-status: 1071ea08a86 Change variable name from accountName to subdomain [Toni Rib]
 app/controllers/integrations/freshbooks_controller.rb       |  4 ++++
 spec/controllers/integrations/freshbooks_controller_spec.rb | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

stash@{1}: WIP on 169348012-connect-to-freshbooks: ba0aa32dc69 Update frontend to call freshbooks connect endpoint [Toni Rib]
 app/controllers/integrations/freshbooks_controller.rb       | 48 +++++++++++++++++++++++++++++++++++++++++-------
 spec/controllers/integrations/freshbooks_controller_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 7 deletions(-)

stash@{2}: WIP on 169348836-backfill-legacy-app-connections: 62ca532dd41 [CASH-926] Move logic for loan_origination_failed email (#51895) [Toni Rib]
stash@{3}: WIP on 169348836-backfill-legacy-app-connections: bf32f6afe76 WIP [Toni Rib]
 app/services/backfills/legacy_app_connections.rb                |  2 +-
 engines/app_ecosystem/app/lib/app_ecosystem/adapters/g_suite.rb |  1 +
 engines/app_ecosystem/app/lib/app_ecosystem/apis/g_suite_api.rb |  9 ++++++++-
 engines/app_ecosystem/app/lib/app_ecosystem/retrier.rb          |  3 ++-
 engines/app_ecosystem/spec/lib/app_ecosystem/retrier_spec.rb    | 25 ++++++++++++++++++++-----
 5 files changed, 32 insertions(+), 8 deletions(-)

stash@{4}: WIP on 170406930-refactor-app-constants: 80c3ea01ba9 Load omniauth config as single config [Toni Rib]
 engines/app_ecosystem/app/lib/app_ecosystem/apis/g_suite_api.rb   |  4 ++--
 engines/app_ecosystem/app/lib/app_ecosystem/apis/office365_api.rb |  4 ++--
 engines/app_ecosystem/app/lib/app_ecosystem/apis/zoom_api.rb      |  4 ++--
 engines/app_ecosystem/app/models/app_ecosystem/app.rb             |  1 +
 engines/app_ecosystem/app/models/app_ecosystem/app_category.rb    |  4 ++--
 engines/app_ecosystem/config/initializers/omniauth.rb             | 12 ++++++------
 engines/app_ecosystem/spec/dummy/config/application.rb            |  7 +++----
 engines/app_ecosystem/spec/dummy/config/environments/test.rb      |  1 +
 engines/app_ecosystem/spec/dummy/db/schema.rb                     |  9 ++++++++-
 9 files changed, 27 insertions(+), 19 deletions(-)

gitlog.pretty

Shows the specified number of commits in a graph format with colored output and useful information.

Code

git log -n $argv --pretty=format:'%Cred%h %Cgreen%an: %Cblue%s' --graph

Usage & Output

  ➾ gitlog.pretty 5
* 8be271a374a Toni Rib: Connect/disconnect freshbooks in app directory
* 64033557490 gusto-ci-service-account-ref-data-cms: Automated payroll reference data update from CMS from 01-17-2020-074720 (#53175)
* 04033531f9e florencelau: [Background Checks] remove old CreateBackgroundCheck mutation (#53121)
* 38f260ccb2c ToniRib: Connect to Freshbooks from App Directory (#53107)
* 26a7c4b384d tomcharles: Always update connection status in app directory whether the flag is active or not (#53158)

branch.commits

Shows the commits on this branch as compared to development.

Code

git log --oneline --left-right HEAD...development | grep '<'

Usage & Output

  ➾ branch.commits
< 8be271a374a Connect/disconnect freshbooks in app directory

branchlist

Shows a pretty output of your local branches, including the name, when you last committed to it, the most recent commit message, and who created it.

Code

git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always|column -ts'|'

Usage & Output

  ➾ branchlist
*tr/169348064-show-freshbooks-connected-status             32 minutes ago  Connect/disconnect freshbooks in app directory                                    Toni Rib
 development                                               64 minutes ago  Automated payroll reference data update from CMS from 01-17-2020-074720 (#53175)  gusto-ci-service-account-ref-data-cms
 tr/169348012-connect-to-freshbooks                        2 hours ago     Change variable name from accountName to subdomain                                Toni Rib
 tr/170586941-fix-rubocop-violations                       2 days ago      Use the stub to fix rubocop exclusions                                            Toni Rib
 tr/169734982-fix-google-auth-bug                          3 days ago      Be very specific about scopes                                                     Toni Rib
 trsc/170706346-add-basic-admin-dashboard-with-auth        3 days ago      Add authorized admins pages                                                       Toni Rib
 trsc/170706346-add-authorized-admins-table                3 days ago      Update migrations to actually use migrant                                         Toni Rib
 tr/169734982-request-the-oauth-scopes-not-openid-connect  4 days ago      Request OAuth 2.0 scopes, not OpenID Connect                                      Toni Rib
 tr/169734982-add-specific-scope-to-oauth2-client          4 days ago      Add specific admin directory scope to GSuite OAuth2 client                        Toni Rib
 tr/169734982-update-oauth-app-connections-correctly       4 days ago      Update the OauthAppConnection with new creds                                      Toni Rib
 tr/169348836-backfill-legacy-app-connections              9 days ago      Refactor legacy app connection backfilling                                        Sofia Carrillo
 tr/169348701-add-event-tracking                           9 days ago      Add current user role id per Becca                                                Toni Rib
 tr/170406930-refactor-app-constants                       2 weeks ago     Use to_sym in omniauth config file                                                Toni Rib
 tr/170406930-add-legacy-to-apps-table                     2 weeks ago     Make legacy a database field                                                      Toni Rib
 tr/170162286-app-connection-mvp_SAVE                      5 weeks ago     Revert "Put basic auth in place"                                                  Toni Rib
 tr/existing-integrations-sandbox_SAVE                     3 months ago    Connect to Quickbooks Desktop                                                     Toni Rib
 master                                                    4 months ago    Revert "[CASH-627] Rename active scope to active_or_upcoming (#44590)" (#44649)   Andrew W. Lee
 tr/add-cypress-spec-for-app-eco_SAVE                      5 months ago    TOTAL WIP DO NOT COMMIT                                                           Toni Rib
 ag/sk/tc/hack-add-cypress_SAVE                            5 months ago    chore: fix auth flow tests                                                        Grex

filediff

What files have been changed on this branch compared to development.

Code

git diff development...HEAD --name-status

Usage & Output

  ➾ filediff
M       app/controllers/integrations/freshbooks_controller.rb
M       spec/controllers/integrations/freshbooks_controller_spec.rb

stash

Creates a stash with the given description.

Code

git stash push -u -m $argv

Usage & Output

  ➾ stash 'freshbooks controller updates'
Saved working directory and index state On 169348064-show-freshbooks-connected-status: freshbooks controller updates
  ➾ stashlist
stash@{0}: On 169348064-show-freshbooks-connected-status: freshbooks controller updates [Toni Rib]
 app/controllers/integrations/freshbooks_controller.rb       |  4 ++++
 spec/controllers/integrations/freshbooks_controller_spec.rb | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

delete_old_branches

Not really a git alias, but this is a fish function I wrote to list out all my local branches, find any that haven't been committed to in the last 2 weeks, and ask if you want to delete them. It also ignores master, development, and anything that ends in _SAVE.

Code

function delete_old_branches
  echo "Current branches:"
  echo '==============================================================='
  branchlist
  echo '==============================================================='

  set -l branchesToDelete "skip"
  set -l branches (git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:green)%(committerdate:relative)')

  for branch in $branches
    if string match --invert -q -r ".*development.*|.*master.*|.*_SAVE|.*hours.*|.*days.*|.*minutes.*" $branch
      set -l splitBranch (string split "|" $branch)
      set -l branchName (string trim $splitBranch[1])
      set branchesToDelete $branchesToDelete $branchName
    end
  end

  set branchesToDelete $branchesToDelete[2..-1]

  echo "The following branches are 2 weeks old or older and can be deleted:"
  for branch in $branchesToDelete; echo $branch; end
  echo '==============================================================='

  read -l -P 'Do you want to proceed with deletion? [y/n] ' confirm

  switch $confirm
    case Y y
      for branch in $branchesToDelete
        git branch -D $branch
      end
      return 0
    case '' N n
      echo "Skipping deletion."
      return 1
  end
end

Usage & Output

  ➾ delete_old_branches
Current branches:
===============================================================
*tr/169348064-show-freshbooks-connected-status             83 minutes ago  Automated payroll reference data update from CMS from 01-17-2020-074720 (#53175)  gusto-ci-service-account-ref-data-cms
 development                                               83 minutes ago  Automated payroll reference data update from CMS from 01-17-2020-074720 (#53175)  gusto-ci-service-account-ref-data-cms
 tr/169348012-connect-to-freshbooks                        2 hours ago     Change variable name from accountName to subdomain                                Toni Rib
 tr/170586941-fix-rubocop-violations                       2 days ago      Use the stub to fix rubocop exclusions                                            Toni Rib
 tr/169734982-fix-google-auth-bug                          3 days ago      Be very specific about scopes                                                     Toni Rib
 trsc/170706346-add-basic-admin-dashboard-with-auth        3 days ago      Add authorized admins pages                                                       Toni Rib
 trsc/170706346-add-authorized-admins-table                3 days ago      Update migrations to actually use migrant                                         Toni Rib
 tr/169734982-request-the-oauth-scopes-not-openid-connect  4 days ago      Request OAuth 2.0 scopes, not OpenID Connect                                      Toni Rib
 tr/169734982-add-specific-scope-to-oauth2-client          4 days ago      Add specific admin directory scope to GSuite OAuth2 client                        Toni Rib
 tr/169734982-update-oauth-app-connections-correctly       4 days ago      Update the OauthAppConnection with new creds                                      Toni Rib
 tr/169348836-backfill-legacy-app-connections              9 days ago      Refactor legacy app connection backfilling                                        Sofia Carrillo
 tr/169348701-add-event-tracking                           9 days ago      Add current user role id per Becca                                                Toni Rib
 tr/170406930-refactor-app-constants                       2 weeks ago     Use to_sym in omniauth config file                                                Toni Rib
 tr/170406930-add-legacy-to-apps-table                     2 weeks ago     Make legacy a database field                                                      Toni Rib
 tr/170162286-app-connection-mvp_SAVE                      5 weeks ago     Revert "Put basic auth in place"                                                  Toni Rib
 tr/existing-integrations-sandbox_SAVE                     3 months ago    Connect to Quickbooks Desktop                                                     Toni Rib
 master                                                    4 months ago    Revert "[CASH-627] Rename active scope to active_or_upcoming (#44590)" (#44649)   Andrew W. Lee
 tr/add-cypress-spec-for-app-eco_SAVE                      5 months ago    TOTAL WIP DO NOT COMMIT                                                           Toni Rib
 ag/sk/tc/hack-add-cypress_SAVE                            5 months ago    chore: fix auth flow tests                                                        Grex
===============================================================
The following branches are 2 weeks old or older and can be deleted:
tr/170406930-refactor-app-constants
tr/170406930-add-legacy-to-apps-table
===============================================================
Do you want to proceed with deletion? [y/n] y
Deleted branch tr/170406930-refactor-app-constants (was 5e2ae339b37).
Deleted branch tr/170406930-add-legacy-to-apps-table (was c593c3ee8e6).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment