Skip to content

Instantly share code, notes, and snippets.

@bloc40
Last active November 2, 2015 21:07
Show Gist options
  • Select an option

  • Save bloc40/9854256c28bff376e28f to your computer and use it in GitHub Desktop.

Select an option

Save bloc40/9854256c28bff376e28f to your computer and use it in GitHub Desktop.

Revisions

  1. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,6 @@ git init
    ```
    ### Or run it for all applications together:
    ```
    cd src
    cd ~/src
    for dir in *; do cd $dir; git init; done
    ```
  2. bloc40 revised this gist Nov 2, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -34,4 +34,9 @@ git config --global init.templatedir '~/.git_template'
    navigate to the project, then:
    ```
    git init
    ```
    ### Or run it for all applications together:
    ```
    cd src
    for dir in *; do cd $dir; git init; done
    ```
  3. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ chmod a+x ~/.git_template/hooks/prepare-commit-msg

    ### Tell Git where to find the hooks
    ```ruby
    git config --global init.templatedir '~/.code/.git_template'
    git config --global init.templatedir '~/.git_template'
    ```

    ### To add the custom hook to a project
  4. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    ### Create a directory to hold Git hooks
    ```ruby
    ```
    mkdir -p ~/.git_template/hooks/
    ```
    ### Add This file to ~/.git_template/hooks/prepare-commit-msg
  5. bloc40 revised this gist Nov 2, 2015. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -25,10 +25,9 @@ fi
    chmod a+x ~/.git_template/hooks/prepare-commit-msg
    ```

    ### Add this lines to the bottom of .gitconfig
    ### Tell Git where to find the hooks
    ```ruby
    [init]
    templatedir = ~/.git_template
    git config --global init.templatedir '~/.code/.git_template'
    ```

    ### To add the custom hook to a project
  6. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ fi
    ```
    ### Make the file executable
    ```
    chmod a+x ~/.git_templates/hooks/prepare-commit-msg
    chmod a+x ~/.git_template/hooks/prepare-commit-msg
    ```

    ### Add this lines to the bottom of .gitconfig
  7. bloc40 revised this gist Nov 2, 2015. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    ### Create a directory to hold Git hooks
    ```ruby
    mkdir -p ~/.git_templates/hooks/
    mkdir -p ~/.git_template/hooks/
    ```
    ### Add This file to ~/.git_templates/hooks/prepare-commit-msg
    ### Add This file to ~/.git_template/hooks/prepare-commit-msg
    ```ruby
    #!/bin/sh

    @@ -28,5 +28,11 @@ chmod a+x ~/.git_templates/hooks/prepare-commit-msg
    ### Add this lines to the bottom of .gitconfig
    ```ruby
    [init]
    templatedir = ~/.git_templates
    templatedir = ~/.git_template
    ```

    ### To add the custom hook to a project
    navigate to the project, then:
    ```
    git init
    ```
  8. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_CO
    fi
    ```
    ### Make the file executable
    ```ruby
    ```
    chmod a+x ~/.git_templates/hooks/prepare-commit-msg
    ```

  9. bloc40 revised this gist Nov 2, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,10 @@ if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_CO
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
    ```
    ### Make the file executable
    ```ruby
    chmod a+x ~/.git_templates/hooks/prepare-commit-msg
    ```

    ### Add this lines to the bottom of .gitconfig
    ```ruby
  10. bloc40 revised this gist Nov 2, 2015. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    ### Add This file to ~/.git_templates/prepare-commit-msg

    ### Create a directory to hold Git hooks
    ```ruby
    mkdir -p ~/.git_templates/hooks/
    ```
    ### Add This file to ~/.git_templates/hooks/prepare-commit-msg
    ```ruby
    #!/bin/sh

  11. bloc40 revised this gist Nov 2, 2015. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### Add This file to ~/.git_templates
    ### Add This file to ~/.git_templates/prepare-commit-msg

    ```ruby
    #!/bin/sh
    @@ -16,4 +16,10 @@ BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
    if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
    ```

    ### Add this lines to the bottom of .gitconfig
    ```ruby
    [init]
    templatedir = ~/.git_templates
    ```
  12. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ### Add This file to ~/.git_templates

    ```
    ```ruby
    #!/bin/sh

    if [ -z "$BRANCHES_TO_SKIP" ]; then
  13. bloc40 revised this gist Nov 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git-message-prepend.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ### Add This file to ~/.git_templates

    ```ruby
    ```
    #!/bin/sh
    if [ -z "$BRANCHES_TO_SKIP" ]; then
  14. bloc40 renamed this gist Nov 2, 2015. 1 changed file with 0 additions and 0 deletions.
  15. bloc40 revised this gist Nov 2, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Prepend Git commit messages with branch name
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    ### Add This file to ~/.git_templates
    ```

    ```ruby
    #!/bin/sh

    if [ -z "$BRANCHES_TO_SKIP" ]; then
  16. bloc40 revised this gist Nov 2, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Prepend Git commit messages with branch name
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ### Add This file to
    ### Add This file to ~/.git_templates
    ```
    #!/bin/sh

    if [ -z "$BRANCHES_TO_SKIP" ]; then
    @@ -14,4 +15,4 @@ BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
    if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi

    ```
  17. bloc40 revised this gist Nov 2, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions Prepend Git commit messages with branch name
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/bin/bash
    ```
    ### Add This file to
    #!/bin/sh

    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=(master develop)
    fi
    @@ -13,4 +14,4 @@ BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
    if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
    ```

  18. bloc40 created this gist Nov 2, 2015.
    16 changes: 16 additions & 0 deletions Prepend Git commit messages with branch name
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/bash
    ```
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=(master develop)
    fi
    BRANCH_NAME=$(git symbolic-ref --short HEAD)
    BRANCH_NAME="${BRANCH_NAME##*/}"
    BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
    BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
    if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
    ```