Skip to content

Instantly share code, notes, and snippets.

@zanthrash
Created February 14, 2021 15:45
Show Gist options
  • Save zanthrash/c0be725421ebd869517a2d961c757a44 to your computer and use it in GitHub Desktop.
Save zanthrash/c0be725421ebd869517a2d961c757a44 to your computer and use it in GitHub Desktop.
My Git Workflow

My Git Workflow

Setup

Git aliases

Add these to your ~/.gitconfig under the [alias] block:

[alias]
    # list commands
    le = log --oneline --decorate
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --stat
    ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
    lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
    ld = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
    lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
    lg = log --graph --oneline --decorate --all
    


    sync = pull --rebase upstream master
    f = checkout -b
    pf = push -u origin
    kf = !sh -c 'git branch -D $1 && git push origin --delete $1' -
    feature = checkout -b
    pushFeature = push -u origin
    killFeature = !sh -c 'git branch -D $1 && git push origin --delete $1' -

Install the Hub CLI

$ brew install hub

Add this to your `~/.gitconfig

[hub]
    host = git.target.com
[github]
    host = git.target.com
    user = [your_git_name]

Add this to your shell aliases:

alias pr='hub pull-request -o'
alias pfpr="git pf && pr"

function take() {
	mkdir -p "$1"
	cd "$1"
}

function copr() {
	echo "Checking out PR $1 to local branch"
	git fetch upstream pull/$1/head:pr-$1
	git co pr-$1
}

Actual Workflow

  1. Fork the repo into personal git
  2. Clone the repo from personal git
  3. Set upstream remote repo to master repo. git remote add upstream git@git.target.com:[org]/[repo].git
  4. Create a local feature branch. git f my_cool_feature_branch_name
  5. HACK AWAY
  6. commit code to feature brach
  7. Sync any upstream changes and resolve conflict if needed: git sync
  8. Cut a PR with pfpr. This will push the feature branch to your forked repo (the pf) then create a PR and open it up in your default browser.
  9. Merge the PR (after a thurough approval process)
  10. Check out master branch locally: git co master
  11. Sync all changes to master: git sync
  12. Clean up local and remote branchs: git kf my_cool_feature_branch_name or git killFeature my_cool_feature_branch_name
  13. PROFIT!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment