-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Let's create the same problem again, but this time use some of the tools on GitHub to solve the problem - let's introduce issues and Pull Requests.
Study this code You've already seen most of it before - what do you think is happening?
Run it!
git co master
git pull origin master
cd $(git root)
mkdir pr-lab
POEM=$(git root)/pr-lab/eeny-meeny-miny-moe.txt
cat <<ENDOFPOEM > $POEM
Eeny, meeny, miny, moe,
Catch a tiger by the toe.
If he hollers, let him go,
Eeny, meeny, miny, moe.
My mother told me to pick
the very best one and you - are - it!"
ENDOFPOEM
git add $POEM && git commit -m "I published a poem"
git tag v01.0.0
git pull origin master && git push --tags origin masterAlways work on an issue
It's an integrated part of the underlying concepts in both Scrum boards and Kanban boards that work only happens for a reason You could say that any change to the code base must be related to a card that is create in forehand. There's always a pupose!
So consequnently - If we want to improive the poem, we first need an issue (task, user story) that instructs us to do so.
So you should go to the webpage on GitHub (gh browse) for this repo and create new issue - assign it to yourself:
title: "Fix the Eeeny Meeny poem"
body: "No rules, just improve whatever you like"
assignee: "@me"
label: "bug"Could have created an issue from the command line?
Of course:
gh issue create \
--title "Fix the Eeeny Meeny poem" \
--body "No rules, just improve whatever you like" \
--assignee "@me" \
--label "bug"
- The entire command is one statement but for readability it spawns multiple lines using
\as line-ending on lines that are continued.
It returns the URL to the newly created issue
Now create a branch which is specifically related to this particular issue.
On the icon panel to the left in your VC Code click the GitHub icon. In the lover panel you see the GitHub issues - since you assigned the issue to your selv it should show up - something like:
The Arrow icon will create a new branch, related to this issue.
The globe will take you to the issue on GitHub in the example (issue 39) the same as gh browse 39.
- Create a branch on your issue.
NOTE: You terminal might show you, that you are still on master but just hit enter once to get the new status in your prompt.
Could have create a branch from an issue from the command line?
Of course:
# Create a branch off issue no. 39
gh issue develop --checkout 39Hold on tight I'll show you how we could even have created and the issue and the branch - in one go:
gh issue develop --checkout $(gh issue create \
--title "Fix the Eeeny Meeny poem" \
--body "No rules, just improve whatever you like" \
--assignee "@me" \
--label "bug" \
| grep -oP "https:.*\/\\K(\\d+)$")
Quite a few elements makes this command semi-advanced:
The gh issue develop command needs to know the issue number of the one just created - we will get that by parsing the output of the gh issue create command.
- The entire
gh issue createcommand is wrapped up in Command Substitution$(...)which is passed to thegh issue developcommand. - The command that created the issue
gh issue createis piped|to another command calledgrep. grepruns a perl-style-Pregular expression which is instructed only to return the actual match-o.- The regular expression
https:.*\/\\K(\\d+)$is passed as a string, so it must escape the special chars:\/and\\. - The regular expression even shortens the match with a don't look back option
\K. Effectively only returning the tailing$integer from the line which containshttps:.
Mind blowing!
Fix the poem
- Open the new poem (
./pr-lab/eeny-meeny-miny-moe.txt) and make some fixes. -
git addyour changes -
git commityour changes -
git push your change
HEY - the push wasn't straight forward - you probably got something like:
fatal: The current branch <USER>/issue11 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin republicdomain/issue11Calm! Theres nothing in git you can't automate - so of course there is a solution to this issue too. As you might have guessed the solution is a setting in you gitconfig file.
push.default -- read all about it!
The pattern setting you are looking for is probably current.
- Try this:
git config --file $(git root)/.gitconfig push.default current
git push
- Go to GitHub and find the commit you just pushed - create a pull request from it!
NOTE: Did you read the output from the git push command - I has a nice surprise!
