Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

Helps you do your job


Overview

This page explains files in my git-utilities repo.

On a Mac:

  1. Get the repo onto your machine using a Git UI or in a Git command line:

    git clone https://github.com/wilsonmar/git-utilities
    
  2. cd into the repo.

  3. (If you don’t have it already) create a folder on the operating system’s path by copying the git-custom-commands folder from within the Git repository into a folder in your home directory.

    Linux people often use /opt/bin, but on a Mac that is a protected area requiring sudo access.

    create a folder under your $HOME folder and put that folder within the system path.

    $HOME/git-custom-commands
    
  4. On a Mac, edit file ~/.bash_profile so the custom command files will be found when they are run on any folder.

    PROTIP: git automatically make files available as a subcommand, just like regular executable scripts.

  5. Exit terminal session windows or re-run the Terminal initialization:

    source ~/.bash_profile
    
  6. cd into the git-custom-commands folder.

  7. Set permissions to execute each file:

    
    chmod 555 *
    
  8. Try the git-echo command, created just so we can verify whether we have it working:

    
    git echo "hello"
    

    You should see response:

    hello
    

    Instead of “hello”, you can type in any phrase.

Python program

A cross-platform Python can be executed.

Graphviz

Seth House did several videos on Git and GitHub, in which he showed use of a utility to create a visualization from the command line. He was nice enough to share it with me.

  1. Install GraphViz using a package manager. On a Mac:

    
    brew install graphviz
    

    This installs dependencies libtiff, webp, gd

    • http://www.graphviz.org/Download_macos.php - graphviz-2.40.1.pkg
    • http://www.graphviz.org/Download_windows.php

  2. Save the file from a text editor into folder

    Alternately, copy the file graph-dag into that folder from the cloned folder.

  3. Set permissions to execute the file:

    
    chmod a+x graph-dag
    
  4. Run the graph-dag that outputs a commit graph using the GraphViz “dot” tool:

    
    git graph-dag HEAD~10.. | dot -Tpng > mygraph.png
    
  5. Additionally, look at the other utilities at:

    https://git.wiki.kernel.org/index.php/ExampleScripts

    • Sorting commits by commit message line count / changed lines ratio
    • Copying all changed files from the last N commits
    • Setting the timestamps of the files to the commit timestamp of the commit which last touched them

Visualization of branches

git log does a good job of illustrating branches, but GitKraken provides this colorful branch graphics:

git-utilities gitkraken dag 579x279

  • The master branch is the light-blue line on the left.

  • The Bug fix branch is the darker-blue line to the right of that.

  • The develop branch is the purple line to the right of that.

ASCII Art

Make some ASCII art from (part of your) history

A - B - C
  \       \
    D - E - F
   

More

This is one of a series on Git and GitHub:

  1. Git and GitHub videos

  2. Why Git? (file-based backups vs Git clone)
  3. Git HEAD (Commitish references)
  4. Git-client based workflows
  5. Git whoops (correct mistakes)
  6. Git rebase
  7. Git interactive merge (imerge)
  8. Git commits with a Tag and Signature

  9. Git custom commands
  10. Git utilities
  11. Git hooks

  12. GitHub data security

  13. TFS vs GitHub
  14. GitHub REST API
  15. GitHub GraphQL API
  16. GitHub PowerShell API Programming
  17. GitHub GraphQL PowerShell Module