Skip to content

GitHub Workflow

iaean edited this page Mar 13, 2023 · 2 revisions

Strongly inspired by k8s community guide.

We love UI's. Because console is another UI, the git hub CLI and the github CLI are used, here.

install github cli...
# install hub binary
curl -sL https://github.com/github/hub/releases/download/v2.12.8/hub-linux-amd64-2.12.8.tgz |\
 sudo tar -C /usr/local/bin -xvzf- --strip-components=2 hub-linux-amd64-2.12.8/bin/hub

# install hub bash completion
curl -sL https://github.com/github/hub/releases/download/v2.12.8/hub-linux-amd64-2.12.8.tgz |\
 sudo tar -C /etc/bash_completion.d -xvzf- --strip-components=2 hub-linux-amd64-2.12.8/etc/hub.bash_completion.sh

# alias hub
eval "$(hub alias -s)"

# install gh
curl -sL https://github.com/cli/cli/releases/download/v2.14.4/gh_2.14.4_linux_amd64.tar.gz |\
 tar -C ~/.local -xvzf- --strip-components=1

# install gh bash completion
eval "$(gh completion -s bash)"
setup your environment...
# HTTPS instead of git or SSH for hub
git config --global hub.protocol https

# HTTPS instead of git or SSH for gh
gh config set git_protocol https --host github.com

# enforce rebasing instead of merging on git pull
git config --global branch.autoSetupRebase remote

export ORG=dns3l
export REP=foo
export USR=bar

# login into github.com
gh auth login
maintainer creates a none empty new upstream on github.com...
mkdir $REP && cd $REP && touch .gitkeep

git init
git add . && git commit -m "It begins."
git branch stable master

# https://developer.github.com/v3/repos/#create
# hub api /orgs/$ORG/repos -F name=$REP
# git remote add -f origin https://github.com/$ORG/$REP
# or instead:
# hub create $ORG/$REP

gh repo create $ORG/$REP --public
gh repo edit $ORG/$REP \
 --description "Hello world." \
 --allow-forking --default-branch master --delete-branch-on-merge \
 --enable-rebase-merge=false --enable-squash-merge=true --enable-merge-commit=false \
 --enable-issues=true --enable-projects=false --enable-wiki=false

git remote add origin https://github.com/$ORG/$REP
git push origin --all
cd .. && rm -Rf $REP

# https://developer.github.com/v3/repos/#edit
# cat <<EOT | hub api /repos/$ORG/$REP -XPATCH --input -
# {
#   "description": "Hello world!",
#   "private": false,
#   "allow_merge_commit": false,
#   "allow_rebase_merge": false
# }
# EOT
developer creates fork on github.com and local clone...
# https://developer.github.com/v3/repos/forks/#create-a-fork
# git clone https://github.com/$ORG/$REP && cd $REP
# hub api -X POST /repos/$ORG/$REP/forks
# git remote rename origin upstream
# git remote add -f origin https://github.com/$USR/$REP
# or instead:
# hub clone $ORG/$REP && cd $REP
# hub fork --remote-name=origin
# or instead:
gh repo fork $ORG/$REP --clone --remote && cd $REP

# IMPORTANT: Never push to upstream
git remote set-url --push upstream no_push
git remote -v

git branch -u origin/master
git branch -a

# enforce rebasing instead of merging
git config branch.autoSetupRebase always
if the fork is already there, developer instead creates local clone only...
git clone https://github.com/$USR/$REP && cd $REP
git remote add upstream https://github.com/$ORG/$REP
# IMPORTANT: Never push to upstream
git remote set-url --push upstream no_push
git remote -v
git branch -a
# enforce rebasing instead of merging
git config branch.autoSetupRebase always
developer branches, publishes local commits to fork and contributes via PR to upstream...
git fetch upstream
git checkout master
git rebase upstream/master

git checkout -b branch

# ...
git commit -m '(Initial) commit.'

# IMPORTANT: Without -h as explicit source...
#            ...hub attempts to push branch to upstream instead of origin!
# hub pull-request -b $ORG:master -h $USR:branch -p -m 'Requesting a (first) pull...'

gh pr create --repo $ORG/$REP -B $ORG:master -H $USR:branch -d \
 --title "It begins with a (first) pull" --body "Let's contribute to upstream"

# Until your PR is merged, still contribute to it.
# ...
git commit -m 'Another commit.'
git push origin

If you have upstream write access, please refrain from using the GitHub UI for creating PRs, because GitHub will create the PR branch inside the main repository rather than inside your fork.

developer deletes branch on clone and fork after PR was merged to upstream...
git checkout master
git branch -d branch
git branch -dr origin/branch
git push origin --delete branch
developer keeps the fork in sync with the upstream...
git fetch upstream
git checkout master
git rebase upstream/master
git push origin
Clone this wiki locally