Skip to content

Instantly share code, notes, and snippets.

@elasticdog
Last active October 17, 2022 14:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elasticdog/164fe1bb75ad645abd30d545382a1542 to your computer and use it in GitHub Desktop.
Save elasticdog/164fe1bb75ad645abd30d545382a1542 to your computer and use it in GitHub Desktop.
Git Triangular Workflow
Copyright (c) 2018, Aaron Bull Schaefer <aaron@elasticdog.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  1. Fork an upstream repo -- I'll use terraform-provider-vault as an example.

  2. Clone your forked copy of the repo:

    git clone git@github.com:elasticdog/terraform-provider-vault.git
    cd terraform-provider-vault/
    
  3. Add the upstream repo as a remote:

    git remote add upstream https://github.com/terraform-providers/terraform-provider-vault.git
    git fetch upstream
    
  4. By default, always push to origin (your forked copy) using the current branch name:

    git config remote.pushdefault origin
    git config push.default current
    
  5. Prevent accidental commits directly on the master branch using a pre-commit hook:

    $ cat .git/hooks/pre-commit 
    #!/usr/bin/env bash
    
    current_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
    
    if [[ $current_branch = 'master' ]]; then
            echo 'Direct commits to the master branch are not allowed.'
            exit 1
    fi
    
  6. Set your local master branch to track upstream/master:

    git branch master -u upstream/master
    
  7. Create a branch whizbang off of upstream master to work on a new feature, and check out the branch:

    git checkout -b whizbang upstream/master
    

License

This Gist, "Git Triangular Workflow" is provided under the terms of the MIT License.

Copyright © 2018, Aaron Bull Schaefer.

These simplified instructions were inspired by Git 2.5, including multiple worktrees and triangular workflows © 2015 by Michael Haggerty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment